要配置底层 WebSocket 服务器,服务器配置中 的信息适用。然而,对于 Jetty,你需要通过 StompEndpointRegistry 设置 HandshakeHandler 和 WebSocketPolicy。

    1. @Configuration
    2. @EnableWebSocketMessageBroker
    3. public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    4. @Override
    5. public void registerStompEndpoints(StompEndpointRegistry registry) {
    6. registry.addEndpoint("/portfolio").setHandshakeHandler(handshakeHandler());
    7. }
    8. @Bean
    9. public DefaultHandshakeHandler handshakeHandler() {
    10. WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
    11. policy.setInputBufferSize(8192);
    12. policy.setIdleTimeout(600000);
    13. return new DefaultHandshakeHandler(
    14. new JettyRequestUpgradeStrategy(new WebSocketServerFactory(policy)));
    15. }
    16. }