Maven中的设置
将打包类型jar
<packaging>jar</packaging>
修改为war
<packaging>war</packaging>
将以下代码
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
替换为
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
让程序启动类继承 SpringBootServletInitializer,并重写configure方法,以WebsocketServerApplication为例
@SpringBootApplication
@EnableAutoConfiguration
public class WebsocketServerApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(WebsocketServerApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(WebsocketServerApplication.class);
}
}
网友评论