1 pom.xml打包方式修改爲war
2移除spring boot自帶的tomcat包
3添加serverlet-api(編譯階段需要)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 移除嵌入式tomcat插件 -->
<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>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
4添加啓動類
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
public class start extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// 注意這裏要指向原先用main方法執行的Application啓動類
return builder.sources(ProductApplication.class);
}
}
5、添加war插件,並取消其對web.xml 的依賴。
打包war項目,必須指向一個web.xml文件,沒有就會報錯,web.xml文件的路徑可配置,如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>webapps\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
由於spring-boot不需要web.xml文件,可以加入以下配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
-