在某种情况下,比如。。。。。。。。。。之下,我们不得不,将springboot打成war包
1、在pom.xml文件中修改
<packaging>war</packaging>
2、移除springboot自带的tomcat
<!--移除自带的tomcat-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
3、在启动类上继承SpringBootServletInitializer
添加以下内容
@SpringBootApplication
@EnableTransactionManagement //开启事务
public class WeiPaoApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run( WeiPaoApplication.class, args );
System.out.println("我是大帅比");
}
/*将springboot项目打包成war*/
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
// 注意这里要指向原先用main方法执行的Application启动类
return builder.sources(WeiPaoApplication.class);
}
}
4、全部处理完后,执行maven命令,跳过测试用例成功,到target文件中。包后缀为 war
mvn clean install -Dmaven.test.skip=true