java webSocket

importorg.springframework.context.annotation.Configuration;

importorg.springframework.messaging.simp.config.MessageBrokerRegistry;

importorg.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;

importorg.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;

importorg.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**

* Modified By :

*/

@Configuration

@EnableWebSocketMessageBroker

public classWebSocketConfigextendsAbstractWebSocketMessageBrokerConfigurer {

/**

* 注册Stomp节点,接受来自客户端的连接

*/

@Override

public voidregisterStompEndpoints(StompEndpointRegistry registry) {

registry.addEndpoint("/webSocket").setAllowedOrigins("*").withSockJS();

}

/**

* 设置消息连接的各种规范信息

*/

@Override

public voidconfigureMessageBroker(MessageBrokerRegistry registry) {

//客户端订阅的地址

//to enable a simple memory-based message broker to carry the greeting messages

// back to the client on destinations prefixed with "/topic".

//创建一个监听的频道

registry.enableSimpleBroker("/topic");

}

}

在调用的类中引入

@Autowired

privateSimpMessagingTemplatetemplate;


你可能感兴趣的:(java webSocket)