导入坐标排除springboot内置的tomcat插件
< 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>
导入servlet-api:
< dependency>
< groupId> javax.servlet</ groupId>
< artifactId> javax.servlet-api</ artifactId>
< scope> provided</ scope>
</ dependency>
修改启动类如下:
import org. springframework. boot. SpringApplication;
import org. springframework. boot. autoconfigure. EnableAutoConfiguration;
import org. springframework. boot. autoconfigure. SpringBootApplication;
import org. springframework. boot. builder. SpringApplicationBuilder;
import org. springframework. boot. web. servlet. support. SpringBootServletInitializer;
@SpringBootApplication
public class BlogApplication extends SpringBootServletInitializer {
public static void main ( String[ ] args) {
SpringApplication. run ( BlogApplication. class , args) ;
}
@Override
protected SpringApplicationBuilder configure ( SpringApplicationBuilder builder) {
return builder. sources ( BlogApplication. class ) ;
}
}
maven编译插件
< build>
< plugins>
< plugin>
< groupId> org.springframework.boot</ groupId>
< artifactId> spring-boot-maven-plugin</ artifactId>
</ plugin>
</ plugins>
</ build>
最后记得不要忘记pack打包方式要改成war包
< parent>
< groupId> org.springframework.boot</ groupId>
< artifactId> spring-boot-starter-parent</ artifactId>
< version> 2.3.0.RELEASE</ version>
< relativePath/>
</ parent>
< groupId> com.wxf</ groupId>
< artifactId> blog</ artifactId>
< version> 0.0.1-SNAPSHOT</ version>
< name> blog</ name>
< description> Demo project for Spring Boot</ description>
< packaging> war</ packaging>
最终在idea环境下即可clean,install打成war包,默认在target目录下复制粘贴出放进tomcat即可。