我用的SpringBoot版本
parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.2</version> <relativePath/> <!-- lookup parent from repository --> /parent>
pom.xml
文件<packaging>war</packaging>
修改依赖
<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> <!--tomcat范围改成provided,告诉它,已经有外部tomcat了,不需要一起打包带走了--> <scope>provided</scope> </dependency>
SpringBootServletInitializer
,并重写configure
方法public class JavaTestApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(JavaTestApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(JavaTestApplication.class); } }
参考链接:https://blog.csdn.net/u012939253/article/details/105530682