之前的项目都是直接打成jar包的,那么如何使用SpringBoot把项目打成war包呢?分为以下三步:
- pom.xml文件中的packing标签改为war
- build标签下添加以下依赖
<build>
<!--打出的war包的名字-->
<finalName>${project.artifactId}</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</pluginManagement>
</build>
- SpringBoot的启动类继承SpringBootServletInitializer类,并且重写方法configure
@SpringBootApplication
public class MainApplication extends SpringBootServletInitializer {
public static void main(String[] args) throws Exception{
SpringApplication.run(MainApplication.class,args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(MainApplication.class);
}
}