Spring Boot + React Chat App using STOMP
Overview
This document explains how to create a real-time chat application using Spring Boot (Backend) and [Link] (Frontend)
with WebSocket and STOMP protocol for message communication.
Technologies Used
- Spring Boot (with WebSocket and STOMP)
- ReactJS (Frontend UI)
- STOMP over SockJS for messaging
- Maven (build tool), npm (frontend)
Backend - Spring Boot Configuration
1. [Link]:
@EnableWebSocketMessageBroker enables broker-based messaging.
registerStompEndpoints registers /ws endpoint for WebSocket handshake.
configureMessageBroker sets destination prefixes.
2. [Link]:
A simple POJO class with sender and content fields.
3. [Link]:
@MessageMapping and @SendTo used to route incoming and outgoing messages.
4. [Link]:
Main class to launch Spring Boot app.
Frontend - [Link]
1. Install packages:
npm install @stomp/stompjs sockjs-client
2. Create [Link]:
- Connects to /ws endpoint using SockJS
- Subscribes to /topic/messages
- Sends messages to /app/send
- Displays all received messages
Running the Application
- Start Backend: ./mvnw spring-boot:run
- Start Frontend: npm start
Ensure Spring Boot is running on port 8080.
Next Steps (Optional Enhancements)
Spring Boot + React Chat App using STOMP
- Add JWT-based Authentication
- Store messages in a database
- Improve UI using Tailwind or Material UI
- Host on cloud (Render, Netlify, Railway, etc.)