Are you running in a Servlet container that supports JSR-356?

java.lang.IllegalArgumentException: No 'javax.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?

將websocket的demo拉入自己的項目報錯,其實顯示的是web容器不包括這個JSR-356,
springboot自帶的有tomcat,所以需要看下你更換的web容器,我換的是undertow容器,所以我的springboot啓動類需要修改一下

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-websocket</artifactId>
 </dependency>

 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-undertow</artifactId>
 </dependency>

這個問題我也是一臉懵逼,也找不到相同的,所以還是仔細觀察才能解決bug。要仔細查看啓動代碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章