Websocket in Spring Boot app - Getting 403 Forbidden

后端 未结 3 861
长发绾君心
长发绾君心 2021-02-02 09:26

Websocket in Spring Boot app - Getting 403 Forbidden

I can connect to the websocket from client using sockjs/stompjs when I run this in eclipse (no spring boot).

<
3条回答
  •  悲哀的现实
    2021-02-02 10:05

    I had a similar issue and fixed it in the WebSocketConfig by setting the allowed origins to "*".

    @Configuration
    @EnableWebSocketMessageBroker
    public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
    
        @Override
        public void registerStompEndpoints(StompEndpointRegistry registry) {
            // the endpoint for websocket connections
            registry.addEndpoint("/stomp").setAllowedOrigins("*").withSockJS();
        }
    
        // remaining config not shown as not relevant
    }
    

提交回复
热议问题