SpringBoot+WebSocket 项目打war包部署到Tomcat报错
本地在idea,WebScoket正常,写了需要ServerEndpointExporter
项目打war包部署到Tomcat报错,,,将ServerEndpointExporter 注释掉就行了
报错:
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'serverEndpointExporter' defined in class path resource
[com/leixing/blog/conf/WebSocketConfig.class]: Invocation of init method
failed; nested exception is java.lang.IllegalStateException:
javax.websocket.server.ServerContainer not available
package com.lx.blog.conf;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* @explain WebSocket
* @author luolei
* @date 2019年8月27日
*/
@Configuration //开启WebSocket支持
//SpringBootTest
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WebSocketConfig {
/**
* 如果用外置tomcat,要注释掉以下代码,否则启动项目会报错,用springboot内置tomcat就得放开以下代码
* 本地在idea,需要下面内容
* 打war包部署到Tomcat,需要去掉下面@Bean的内容
*/
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}