一、引言
最近接了个相当于外包的项目,在他们项目中集成一个WebSocket的服务端,嗯功能其实不难,但是前方有坑。
本文主要来记录一下,如果没有了百度,在项目启动就抛异常、或者一些奇奇怪怪的问题,靠自己怎么去排查问题,同样有时候并不是所有的问题都能够通过搜索引擎来解决。
除了外力,那我们就只剩下:异常信息、源码、和本身经验。
项目框架用的是SpringBoot,然后集成WebSocket就行,在集成的过程中,其中有一步需要配置一个Bean。
@Component
public class WsConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
ServerEndpointExporter serverEndpointExporter = new ServerEndpointExporter();
return serverEndpointExporter;
}
然后在项目启动的时候抛出了异常信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name serverEndpointExporter defined in class path resource [org/springblade/modules/hol/config/WsConfig.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:1769)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:863)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)
at org.springblade.core.launch.BladeApplication.run(BladeApplication.java:50)
at org.springblade.Application.main(Application.java:18)
Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
at org.springframework.util.Assert.state(Assert.java:73)
at org.springframework.web.socket.server.standard.ServerEndpointExporter.afterPropertiesSet(ServerEndpointExporter.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1828)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1765)
... 16 common frames omitted
二、问题分析
Error creating bean with name serverEndpointExporter defined in class path resource [org/springblade/modules/hol/config/WsConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
通过异常的第一行就能够得知,是在Spring创建serverEndpointExporterbean的时候抛出来的,是这个WsConfig类,原因是:ServerContainer这个对象不可使用。
抛出异常的类是:AbstractAutowireCapableBeanFactory.java:1769
分析到这里就能够得知,是在spring创建serverEndpointExporter的时候异常了,那么异常的原因是什么呢?,为什么ServerContainer不可用呢?接着分析
通过控制台点击到对应的源码信息如下:AbstractAutowireCapableBeanFactory.java:1769
protected Object initializeBean(String beanName, Object bean, @Nullable RootBeanDefinition mbd) {
if (System.getSecurityManager() != null) {
AccessController.doPrivileged((PrivilegedAction
原文链接:https://www.w1ym.com/82513/,转载请注明出处~~~
评论0