将springboot打成war包

1. pom.xml
(1)修改依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
改为:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>


<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
(2)build位置增加
<build>
。。。。。。。
<finalName>AAA</finalName>
</build>
(3)改为war包
在(2)相同的pom.xml中:<packaging>war</packaging>

2.入口启动文件
改为:
@SpringBootApplication
@EnableAspectJAutoProxy
@EnableScheduling
@EnableCaching
public class WarStarterApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(WarStarterApplication.class);
}

public static void main(String[] args) {
SpringApplication.run(WarStarterApplication.class, args);
}
}

3. 增加web.xml
位置:入口启动文件所在模块,增加src->main->webapp->WEB-INF->web.xml
内容为空,如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">
</web-app>

posted on 2021-08-26 15:19  谦虚好学每一天  阅读(245)  评论(0)    收藏  举报

导航