最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot整合websocket后啟動報錯(javax.websocket.server.ServerContainer not available)

 更新時間:2024年01月15日 14:57:09   作者:清如許.  
這篇文章主要介紹了springboot整合websocket后啟動報錯(javax.websocket.server.ServerContainer not available),通過分析錯誤信息、排查代碼和配置,找出問題的根源,并給出相應(yīng)的解決方案,感興趣的可以了解一下

一、場景

Springboot使用@ServerEndpoint來建立websocket鏈接。引入依賴。

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

配置Websocket

@Configuration  
@EnableWebSocket  
public class WebSocketConfig {  
  
    @Bean  
    public ServerEndpointExporter serverEndpointExporter() {  
        return new ServerEndpointExporter();  
    }  
}

二、報錯信息

springboot項目添加websocket依賴后運(yùn)行測試類報如下錯誤:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2024-01-15 10:27:30.908 ERROR 20552 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverEndpointExporter' defined in class path resource [org/springblade/lab/external/webScoket/WebSocketConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$211/1936375962.getObject(Unknown Source)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:929)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:591)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:164)
    at org.springblade.core.launch.BladeApplication.run(BladeApplication.java:49)
    at org.springblade.Application.main(Application.java:33)
Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
    at org.springframework.util.Assert.state(Assert.java:76)
    at org.springframework.web.socket.server.standard.ServerEndpointExporter.afterPropertiesSet(ServerEndpointExporter.java:107)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1863)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1800)
    ... 17 common frames omitted

三、排查思路

報的錯誤是創(chuàng)建ServerEndpointExporterBean失敗,原因是ServerContainer不可用,那么我們就去看到ServerContainer在ServerEndpointExporter中是怎么注入的。

點(diǎn)進(jìn)去ServerEndpointExporter()類,
在第49行代碼打上debug跑一下

在這里插入圖片描述

選中第50行代碼,右鍵,執(zhí)行計算,或者使用快捷鍵Crtl+U

在這里插入圖片描述

計算結(jié)果發(fā)現(xiàn)是null

在這里插入圖片描述

四、分析原因

為什么servletContext會返回null,定位到 ServerContainer 類,發(fā)現(xiàn)他是一個接口,那必定注入的時候是有相應(yīng)的實(shí)現(xiàn)類,點(diǎn)擊查看實(shí)現(xiàn),居然有五個實(shí)現(xiàn)類,那就可以推斷是依賴沖突導(dǎo)致不知道要注入哪個實(shí)現(xiàn),最后獲取Bean的時候返回了null。

點(diǎn)進(jìn)去getAttribute方法,查看實(shí)現(xiàn)類

在這里插入圖片描述

這里有五個實(shí)現(xiàn)類,三個是tomcat的,一個是undertow的,還有一個是springframework的,所以解決辦法就是排除掉其他的實(shí)現(xiàn)類,只保留springframework這個就行。

五、解決辦法

安裝Maven Helper插件,打開項目的pom.xml文件,點(diǎn)擊pom文件左下角的Dependency Analyzer排除掉多余的依賴。

在這里插入圖片描述

最終結(jié)果:

      <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>

    <!--websocket服務(wù)-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
             <!--添加以下排除方法-->
            <exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>

再次啟動,一切正常!

到此這篇關(guān)于springboot整合websocket后啟動報錯(javax.websocket.server.ServerContainer not available)的文章就介紹到這了,更多相關(guān)springboot websocket啟動報錯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Spring boot框架下的RabbitMQ消息中間件詳解

    Spring boot框架下的RabbitMQ消息中間件詳解

    這篇文章詳細(xì)介紹了Spring Boot框架下的RabbitMQ消息中間件的基本概念、消息傳輸模型、環(huán)境準(zhǔn)備、Spring Boot集成以及消息生產(chǎn)和消費(fèi),感興趣的朋友跟隨小編一起看看吧
    2025-01-01
  • Mybatis實(shí)現(xiàn)分頁的注意點(diǎn)

    Mybatis實(shí)現(xiàn)分頁的注意點(diǎn)

    Mybatis提供了強(qiáng)大的分頁攔截實(shí)現(xiàn),可以完美的實(shí)現(xiàn)分功能。下面小編給大家分享小編在使用攔截器給mybatis進(jìn)行分頁所遇到的問題及注意點(diǎn),需要的朋友一起看看吧
    2017-07-07
  • IntelliJ IDEA設(shè)置Tabs實(shí)現(xiàn)同時打開多個文件且分行顯示

    IntelliJ IDEA設(shè)置Tabs實(shí)現(xiàn)同時打開多個文件且分行顯示

    今天小編就為大家分享一篇關(guān)于IntelliJ IDEA設(shè)置Tabs實(shí)現(xiàn)同時打開多個文件且分行顯示,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • Struts2框架初學(xué)接觸

    Struts2框架初學(xué)接觸

    本文主要給大家從初學(xué)者的角度介紹了Struts2框架結(jié)構(gòu)和基本頁面代碼等內(nèi)容,一起來學(xué)習(xí)一下。
    2017-11-11
  • IDEA解決maven包沖突easypoi NoClassDefFoundError的問題

    IDEA解決maven包沖突easypoi NoClassDefFoundError的問題

    這篇文章主要介紹了IDEA解決maven包沖突easypoi NoClassDefFoundError的問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • 詳解Java中的mapstruct插件使用

    詳解Java中的mapstruct插件使用

    mapstruct 的插件是專門用來處理 domin 實(shí)體類與 model 類的屬性映射的,我們只需定義 mapper 接口,mapstruct 在編譯的時候就會自動的幫我們實(shí)現(xiàn)這個映射接口,避免了麻煩復(fù)雜的映射實(shí)現(xiàn),對Java?mapstruct使用相關(guān)知識感興趣的朋友一起看看吧
    2022-04-04
  • Netty通道的容器屬性Attribute詳解

    Netty通道的容器屬性Attribute詳解

    這篇文章主要介紹了Netty通道的容器屬性Attribute詳解,Netty中的Channel通道類,有類似于Map的容器功能,可以通過鍵值對的形式來保存任何Java Object的值,一般來說可以存放一些與通道實(shí)例相關(guān)聯(lián)的屬性,比如說服務(wù)期端的ServerSession會話實(shí)例,需要的朋友可以參考下
    2023-12-12
  • springboot實(shí)現(xiàn)postman中form-data傳參實(shí)現(xiàn)過程

    springboot實(shí)現(xiàn)postman中form-data傳參實(shí)現(xiàn)過程

    在項目場景開發(fā)中,對接需求要求使用POST請求傳form-data數(shù)據(jù),使用HttpClient請求時遇到了415錯誤,后改為restTemplate,封裝參數(shù)時使用LinkedMultiValueMap對象以解決參數(shù)無法正確解析的問題
    2026-04-04
  • 詳解如何獲取java中類的所有對象實(shí)例

    詳解如何獲取java中類的所有對象實(shí)例

    如何在運(yùn)行時獲取一個Java類的所有對象實(shí)例呢,本文給大家介紹一種底層實(shí)現(xiàn)的方式,基于jvmti,代碼用C++實(shí)現(xiàn),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-10-10
  • SpringBoot Arthas實(shí)現(xiàn)線上監(jiān)控診斷

    SpringBoot Arthas實(shí)現(xiàn)線上監(jiān)控診斷

    本文主要介紹了SpringBoot Arthas實(shí)現(xiàn)線上監(jiān)控診斷,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2026-03-03

最新評論

枣庄市| 莫力| 汽车| 望城县| 明溪县| 芦山县| 托里县| 静海县| 天长市| 阜南县| 禹州市| 崇礼县| 麻栗坡县| 监利县| 桐城市| 赣州市| 海盐县| 金秀| 山东省| 大余县| 焉耆| 新绛县| 宜川县| 台前县| 福贡县| 武义县| 嫩江县| 峨眉山市| 九江县| 望都县| 灌阳县| 格尔木市| 锦屏县| 杨浦区| 冕宁县| 伊宁市| 赣榆县| 敦煌市| 通河县| 韶山市| 富民县|