spring-boot + websocket 打包问题汇总

来源:互联网 发布:男士手表推荐 知乎 编辑:程序博客网 时间:2024/06/15 18:55

1.springboot打包工程时不需要tomcat插件支持添加生命周期使得tomcat插件无效

<dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-tomcat</artifactId>    <scope>provided</scope></dependency>

2.报错:Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available
这个问题好像是Spring的bug,解决方法很简单,mvn package命令打包时,跳过test步骤,不测试直接打包 使用命令mvn package -DskipTests 打包即可

3.将war包放到tomcat下运行时报错,No suitable default RequestUpgradeStrategy found,这个问题更加奇怪,在网上搜索后发现只需要添加依赖:

<dependency>    <groupId>org.eclipse.jetty.websocket</groupId>    <artifactId>websocket-server</artifactId>    <version>9.4.7.v20170914</version>    <scope>test</scope></dependency>

即可解决问题,这个问题也是十分诡异

以上就是我在springboot+websocket打包到tomcat下运行时遇到的错误

问题2与3均是比较诡异的问题,如果有人知道是什么原因造成,如何解决欢迎回复

原创粉丝点击