主要有以下几个步骤:
1. 在pom文件中添加 <packaging>war</packaging>
2.排除内置tomcat,添加一个依赖即可,scope要设置为provided,打包时就不会把该依赖打包进去
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
3.添加打包插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml> <!--没有web.xml时配置这个-->
<warName>demo<warName> <!--war包重新命名-->
</configuration>
</plugin>
</plugins>
</build>
4.排除test文件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests> <!--不打包test文件-->
</configuration>
</plugin>
5.修改启动类,继承SpringBootServletInitializer
public class DemoApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication .class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication .class, args);
}
}
网友评论