因为Springboot已经内嵌Tomcat了,所以一般不推荐Springboot打包成war包,因为war包是需要服务器的。一般打包成lib包即可。
第一步:
在pom.xml文件中导入Tomcat的依赖:
<!--打包方式jar/war-->
<packaging>war</packaging>
<!-- 打包成war包时一定要用这个依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
第二步:
修改启动类,主要是重写configure方法:
@SpringBootApplication
@MapperScan(basePackages = "com.ysw.dao")
@EnableSwagger2
public class MishopApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MishopApplication.class, args);
}
protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
return application.sources(MishopApplication.class);
}
}
第三步:
清理maven中的垃圾文件:
第四步:
生成war包文件,完成!
其余的部署操作参考网上的部署即可。