Context initialization failed org.springframework.beans.factory.BeanCreationException

本文详细解析了在Spring框架中配置WebSocket时遇到的ContextInitializationFailed异常,提供了针对Jetty和Tomcat服务器的具体解决方案,通过添加必要的依赖来解决RequestUpgradeStrategy缺失的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

严重: Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘webSocketHandlerMapping’ defined in class path resource [org/springframework/web/socket/config/annotation/DelegatingWebSocketConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method ‘webSocketHandlerMapping’ threw exception; nested exception is java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) 
at … 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method ‘webSocketHandlerMapping’ threw exception; nested exception is java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found 
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) 
at … 
Caused by: java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found 
at org.springframework.web.socket.server.support.DefaultHandshakeHandler.initRequestUpgradeStrategy(DefaultHandshakeHandler.java:127) 
at …

出现上述异常,是由于缺少RequestUpgradeStrategy 
对于jetty,需要添加如下依赖

1     <dependency>
2         <groupId>org.eclipse.jetty.websocket</groupId>
3         <artifactId>websocket-server</artifactId>
4         <version>9.3.3.v20150827</version>
5         <scope>provided</scope>
6     </dependency>

对于tomcat,需要添加如下依赖

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-websocket</artifactId>
        <version>8.0.23</version>
        <scope>provided</scope>
    </dependency>

在poem.xml文件中添加这两个依赖后成功解决

 

原文:https://blog.youkuaiyun.com/manerfan/article/details/48526681 
来源:优快云

转载于:https://www.cnblogs.com/keenoooo/p/10235593.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值