1.设置打包类型为warjava
<packaging>war</packaging>
2.若是须要经过命令行的方式启动,须要增长以下设置web
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot.version}</version> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>
说明:这样在war包中/META-INF/MANIFEST.MF中增长信息spring
Start-Class: com.xxx.Application Spring-Boot-Classes: WEB-INF/classes/ Spring-Boot-Lib: WEB-INF/lib/ Spring-Boot-Version: 2.0.2.RELEASE Created-By: Apache Maven 3.5.3 Build-Jdk: 1.8.0_172 Main-Class: org.springframework.boot.loader.WarLauncher
其中:apache
Start-Class为标注为@SpringBootApplication的类maven
@SpringBootApplication public class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(this.getClass()); } public static void main(String[] args) throws Exception { SpringApplication.run(Application.class, args); } }
其余信息不用管,是spring boot loader读取的,Main-Class为WarLauncher表示启动war,还有JarLauncher表示启动jar。ide
3.若是工程中没有web.xml文件,那么须要增长设置,避免maven打包报错spring-boot
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.2.1</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>
4.设置spring bootui
有两种方式来引入spring bootthis
a)在parent节点指定spa
b)在dependencyManagement节点引入,同时设置<type>pom</type><scope>import</scope>