admin管理员组

文章数量:1390728

I am trying to set up a WebSocket server using Spring Boot and i tried to connect to it using Postman (New Request → WebSocket). However, I keep getting the following error response:

Error: Unexpected server response: 200

This is my WebSocketConfig.java

import .springframework.context.annotation.Configuration;
import .springframework.messaging.simp.config.MessageBrokerRegistry;
import .springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import .springframework.web.socket.config.annotation.StompEndpointRegistry;
import .springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic"); 
        config.setApplicationDestinationPrefixes("/app"); 
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/ws") 
            .setAllowedOrigins("*").withSockJS(); 
        ;
    }
}

This is my security config


    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        // @formatter:off
        http
            .csrf().disable() // 

本文标签: javaSpring Websocket configurationStack Overflow