spring-boot项目布到tomcat容器下部署
一、修改打包形式 在pom.xml里设置 `war`
<packaging>war</packaging>
二、移除嵌入式tomcat插件 在pom.xml里找到spring-boot-starter-web依赖节点,在其中添加如下代码,
1 <dependency> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-web</artifactId> 4 <!-- 移除嵌入式tomcat插件 --> 5 <exclusions> 6 <exclusion> 7 <groupId>org.springframework.boot</groupId> 8 <artifactId>spring-boot-starter-tomcat</artifactId> 9 </exclusion> 10 </exclusions> 11 </dependency>
三、添加servlet-api的依赖
1 <dependency> 2 <groupId>javax.servlet</groupId> 3 <artifactId>javax.servlet-api</artifactId> 4 <version>3.1.0</version> 5 <scope>provided</scope> 6 </dependency>
四、修改启动类,并重写初始化方法
1 /** 2 * @Author: 3 */ 4 @SpringBootApplication 5 @ServletComponentScan 6 @MapperScan("com.esint.mt.*.mapper") 7 public class MtApplication extends SpringBootServletInitializer { 8 public static void main(String[] args) { 9 SpringApplication.run(MtApplication.class, args); 10 } 11 12 /*将springboot项目打包成war*/ 13 @Override 14 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 15 // 注意这里要指向原先用main方法执行的Application启动类 16 return builder.sources(MtApplication.class); 17 } 18 19 @PostConstruct 20 void setDefaultTimezone() { 21 TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai")); 22 } 23 }