我想拥有相当于这个XML配置(采用Here),但是使用Java配置:
<bean id="customHandler" class="app.wsock.CustomHandler"/>
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/foo">
<websocket:handshake-handler ref="customHandler"/>
</websocket:stomp-endpoint>
<websocket:simpl-broker prefix="/topic,/queue" />
</websocket:message-broker>
我的目标是根据一些标准建立一个限制与我的STOMP端点连接的类(即:到他的websocket)。
我不想使用XML配置我的端点,如何将该代码段转换为Java Config?
答案 0 :(得分:4)
这样的事情:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Bean
public HandshakeHandler handshakeHandler() {
return new app.wsock.CustomHandler();
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/foo").setHandshakeHandler(handshakeHandler());
}
@Override
public void configureMessageBroker(MessageBrokerRegistry configurer) {
configurer.enableStompBrokerRelay("/topic", "/queue");
}
}