Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 57

    WebSockets

    WebSockets give you persistent, bidirectional connections — the right tool for chat, live dashboards, notifications.

    Course progress0%
    Focus
    2 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    WebSockets give you persistent, bidirectional connections — the right tool for chat, live dashboards, notifications. Spring's STOMP-over-WebSocket abstraction layers messaging semantics on top.

    Informative example

    ts
    @Configuration @EnableWebSocketMessageBroker
    public class WsConfig implements WebSocketMessageBrokerConfigurer {
    public void registerStompEndpoints(StompEndpointRegistry r) {
    r.addEndpoint("/ws").setAllowedOriginPatterns("*").withSockJS();
    }
    public void configureMessageBroker(MessageBrokerRegistry r) {
    r.enableSimpleBroker("/topic"); // or RabbitMQ for clusters
    r.setApplicationDestinationPrefixes("/app");
    }
    }
    @Controller
    public class ChatController {
    @MessageMapping("/chat") // client sends to /app/chat
    @SendTo("/topic/messages") // server broadcasts
    public ChatMessage send(ChatMessage in) { return in; }
    }
    Ready to mark this lesson complete?Track your journey across the entire course.