1. The first packaging of jar into war
<packaging>war</packaging>
2. Add dependence
<!--添加servlet-api的依赖,用来打war包 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
3. Remove or modify the built-tomcat built for the external toncat
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <!--移除嵌入式tomcat插件--> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
<! - use springboot comes with tomcat ->
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
4. Start Modify SpringBootServletInitializer class inherits and overrides a method in which configure
The method of rewriting code:
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builber){ //此处Application.class替换为springboot默认启动类 return builber.sources(KndApplication.class); }
5.IDEA use maven command first and then clean package, clean look, the smaller the chance of error,
If the eclipse right-click the project, select run as-> maven clean, then run as-> maven install.
Extended:
springboot jar packaging start and stop: https://blog.csdn.net/qq_42307369/article/details/101065248