是否可以同时使用@EnableWebSocket和@EnableWebSocketMessageBroker?

时间:2019-06-07 04:54:48

标签: spring-boot websocket

如果我既有普通的websockets又有带有脚踩的websockets,可以在配置文件中一起使用@EnableWebSocket和@EnableWebSocketMessageBroker吗?配置会有冲突吗?

当我同时使用两个注释时,它会按预期工作。但是,当我删除其中之一时,它不起作用

这是我的配置文件:

@Configuration
@EnableWebSocketMessageBroker
@EnableWebSocket
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer, WebSocketConfigurer {
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry
                .addEndpoint("/ws")
                .setAllowedOrigins("*")
                .addInterceptors(handshakeInterceptor())
                .withSockJS();
    }

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

    @Bean
    public HttpHandshakeInterceptor handshakeInterceptor() {
        return new HttpHandshakeInterceptor();
    }

    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new UploadWSHandler(), "/binary").setAllowedOrigins("*");
    }
}

0 个答案:

没有答案