`

SpringBoot使用websocket的注解@ServerEndpoint与@Component

阅读更多
@Component默认是单例
@ServerEndpoint 每个客户端连接,又新生成一个实例,

在@OnOpen方法中,每个客户端连接时,打印this或this.hashCode()值都不相同,说明新new了实例。


使用springboot的唯一区别是要@Component声明下,而使用独立容器是由容器自己管理websocket的,但在springboot中连容器都是spring管理的。
虽然@Component默认是单例模式的,但springboot还是会为每个websocket连接初始化一个bean,所以可以用一个静态set保存起来。


详细见 https://www.cnblogs.com/bianzy/p/5822426.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics