springBoot打war包部署tomcat
1、修改maven的pom.xml文件
<packaging>war</packaging>
2、排除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>
3、添加tomcat依赖,该依赖不打包到war包中
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <!--scope改为provided 表示打包是省略 此项--> <scope>provided</scope> </dependency>
4、配置启动类
首先需要继承SpringBootServletInitializer抽象类
class EshibernApplication extends SpringBootServletInitializer
实现configure方法
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){ return builder.sources(EshibernApplication.class); }
完整代码如下
@SpringBootApplication public class EshibernApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(EshibernApplication.class,args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){ return builder.sources(EshibernApplication.class); } }
5、通过maven打包
mvn clean package -Dmaven.test.skip=true
6、将war包放入tomcat的webapps目录中
7、启动tomcat。