Maven中的設(shè)置
將打包類型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);
}
}