1.修改pom.xml(移除嵌入式tomcat插件,并添加servlet-api的依赖)
<!--war包部署需要-->
<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>
<!--war包部署需要 servlet-api的依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
2.修改启动类(继承 SpringBootServletInitializer 并重写 configure 方法)
public class application extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(application .class);
}
public static void main(String[] args) {
SpringApplication.run(application .class, args);
System.out.println("------ scl-admin启动成功------ ");
}
}
3.打war包
修改pom.xml <packaging>war</packaging>
run->pageck->去target目录查看 war文件
4.把war文件放入tomcat webapp目录,启动tomcat