A simple real-time chat application built with Spring Boot and WebSockets. Perfect for learning how WebSocket communication works or as a starting point for your own chat features.
This app lets multiple users chat with each other in real-time. When someone sends a message, everyone else sees it instantly without needing to refresh the page. It's like a basic version of Slack or Discord, but much simpler.
- Spring Boot 3.5.5 - The main framework that holds everything together
- WebSockets - For real-time bidirectional communication
- STOMP - A messaging protocol that works over WebSockets
- Thymeleaf - For rendering the web pages
- Tailwind CSS → Clean, responsive, and modern UI styling
- Lombok - To reduce boilerplate code (goodbye, endless getters and setters!)
- SockJS - Fallback options when WebSockets aren't available
-
Make sure you have Java 17 or higher installed
java --version
-
Clone the repository (or however you got this code)
-
Navigate to the project directory
cd your-chat-app-folder -
Run the application
./mvnw spring-boot:run
Or if you're on Windows:
mvnw.cmd spring-boot:run
-
Open your browser and go to
http://localhost:8080/chat -
Open another tab or browser window to
http://localhost:8080/chatand start chatting between the windows!
src/main/java/com/chat/app/
├── AppApplication.java # Main Spring Boot application
├── config/
│ └── WebSocketConfig.java # WebSocket configuration
├── controller/
│ └── ChatController.java # Handles chat messages
└── model/
└── ChatMessage.java # Message data structure
- WebSocket Connection: When you visit
/chat, your browser establishes a WebSocket connection to/chatendpoint - Send Message: When you type a message, it gets sent to
/app/sendMessage - Broadcast: The server receives the message and broadcasts it to all connected clients via
/topic/messages - Real-time Updates: Everyone subscribed to
/topic/messagesreceives the new message instantly
- ✅ Real-time messaging
- ✅ Multiple users can chat simultaneously
- ✅ Tailwind CSS styling for a modern, responsive UI
- ✅ Simple and clean setup
- ✅ Works across different browser tabs/windows
- ✅ SockJS fallback for better compatibility
Want to make this your own? Here are some ideas:
- Add user authentication and display usernames
- Store chat history in a database
- Add different chat rooms/channels
- Implement private messaging
- Add message timestamps
- Create a nicer frontend with CSS/JavaScript
- Add emoji support
- Implement message editing/deletion
Port 8080 already in use?
- Change the port in
application.properties:server.port=8081
Messages not showing up?
- Check the browser console for WebSocket connection errors
- Make sure you're connected to the right URL
- Try refreshing the page
Can't build the project?
- Make sure you have Java 17+ installed
- Try
./mvnw clean installfirst
Feel free to fork this project and add your own features! It's a great way to learn about WebSockets and real-time applications.