作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在使用该类配置我的 Spring Websocket
public class WebSocketConfig extends WebSocketMessageBrokerConfigurationSupport
public class SampleJettyWebSocketsApplication implements WebSocketConfigurer
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry)
@Bean
public DefaultHandshakeHandler handshakeHandler()
最佳答案
WebSocketMessageBrokerConfigurationSupport
实现是 DelegatingWebSocketMessageBrokerConfiguration
通过 @EnableWebSocketMessageBroker
配置.您在自定义代码中只需要 WebSocketMessageBrokerConfigurer
执行。而那个注入(inject)到 DelegatingWebSocketMessageBrokerConfiguration
:
@Autowired(required = false)
public void setConfigurers(List<WebSocketMessageBrokerConfigurer> configurers) {
@Configuration
@EnableWebSocketMessageBroker
static class ServerConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Bean
public DefaultHandshakeHandler handshakeHandler() {
return new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy());
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws")
.setHandshakeHandler(handshakeHandler())
.setAllowedOrigins("http://foo.com")
.addInterceptors(new HandshakeInterceptor() {
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response,
WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
return request.getHeaders().getOrigin() != null;
}
@Override
public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response,
WebSocketHandler wsHandler, Exception exception) {
}
})
.withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry configurer) {
configurer.setApplicationDestinationPrefixes("/app")
.enableSimpleBroker("/topic", "/queue");
}
}
关于Spring Websocket 配置 : using WebSocketMessageBrokerConfigurationSupport and WebSocketConfigurer together - how?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43637864/
我目前正在使用该类配置我的 Spring Websocket public class WebSocketConfig extends WebSocketMessageBrokerConfigurat
我是一名优秀的程序员,十分优秀!