问题:
由于电脑重装系统,导致idea重新导入公司项目,结果spring boot项目启动报错:
idea后台报错信息:
2018-12-17 17:35:34.560 ERROR 14720 --- [ main] o.s.boot.SpringApplication : Application startup failedorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverEndpointExporter' defined in class path resource [tk/mybatis/springboot/websocket/WebSocketConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.socket.server.standard.ServerEndpointExporter]: Factory method 'serverEndpointExporter' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/websocket/DeploymentExceptionat org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.4.0.RELEASE.jar:1.4.0.RELEASE]at tk.mybatis.springboot.BussnessApplication.main(BussnessApplication.java:62) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.socket.server.standard.ServerEndpointExporter]: Factory method 'serverEndpointExporter' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/websocket/DeploymentExceptionat org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]... 18 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/websocket/DeploymentExceptionat tk.mybatis.springboot.websocket.WebSocketConfig.serverEndpointExporter(WebSocketConfig.java:11) ~[classes/:na]at tk.mybatis.springboot.websocket.WebSocketConfig$$EnhancerBySpringCGLIB$$97e83690.CGLIB$serverEndpointExporter$0(<generated>) ~[classes/:na]at tk.mybatis.springboot.websocket.WebSocketConfig$$EnhancerBySpringCGLIB$$97e83690$$FastClassBySpringCGLIB$$608668bf.invoke(<generated>) ~[classes/:na]at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.1.RELEASE.jar:4.3.1.RELEASE]at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.1.RELEASE.jar:4.3.1.RELEASE]at tk.mybatis.springboot.websocket.WebSocketConfig$$EnhancerBySpringCGLIB$$97e83690.serverEndpointExporter(<generated>) ~[classes/:na]at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_192]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_192]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_192]at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_192]at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.1.RELEASE.jar:4.3.1.RELEASE]... 19 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.websocket.DeploymentExceptionat java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_192]at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_192]at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_192]at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_192]... 30 common frames omitted
后台代码:
package tk.mybatis.springboot.websocket;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;@Configuration
public class WebSocketConfig {@Beanpublic ServerEndpointExporter serverEndpointExporter (){return new ServerEndpointExporter();}
}
解决:
把控制台信息翻译过来的意思就是:
在类路径资源[tk / mybatis / springboot / websocket / WebSocketConfig.class]中定义名为'serverEndpointExporter'的bean时出错。
既然创建Bean失败,那我去掉@Bean试试,抱着尝试的心理去试,结果ok,控制台不再报错了。
启动成功:如图: