在pom.xml文件中,将打包方式改为war:
1
|
<packaging>war</packaging>
|
然后添加如下的Tomcat依赖配置,覆盖Spring Boot自带的Tomcat依赖:
1 2 3 4 5
|
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
|
在<build></build>
标签内配置项目名(该配置类似于server.context-path=mrbird):
1 2 3 4 5 6
|
... <build> ... <finalName>mrbird</finalName> </build> ...
|
添加启动类ServletInitializer:
1 2 3 4 5 6 7 8 9
|
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer;
public class extends SpringBootServletInitializer { protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class); } }
|
其中Application为Spring Boot的启动类。
准备完毕后,运行mvn clean package
命令即可在target目录下生产war包:
近期评论