标签:static api Servle enc 控制台 tomcat etc builder java
1.去除Springboot内嵌Tomcat依赖
1 <dependency> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-web</artifactId> 4 <exclusions> 5 <!-- 去除内嵌tomcat --> 6 <exclusion> 7 <groupId>org.springframework.boot</groupId> 8 <artifactId>spring-boot-starter-tomcat</artifactId> 9 </exclusion> 10 </exclusions> 11 </dependency>
2.引入servlet的依赖
1 <!--添加servlet的依赖 --> 2 <dependency> 3 <groupId>javax.servlet</groupId> 4 <artifactId>javax.servlet-api</artifactId> 5 <scope>provided</scope> 6 </dependency>
3.单独引入Tomcat依赖
1 <dependency> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-tomcat</artifactId> 4 <scope>provided</scope> 5 </dependency>
4.打包方式为war包
<packaging>war</packaging> <dependencies> ... </dependencies>
5.让Springboot启动类继承SpringBootServletInitializer,重写configure方法
1 @SpringBootApplication 2 public class JobSpiderApplication extends SpringBootServletInitializer { 3 4 public static void main(String[] args) { 5 SpringApplication.run(JobSpiderApplication.class, args); 6 } 7 8 @Override 9 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 10 return builder.sources(this.getClass()); 11 } 12 13 }
6.项目右键->Run As->Maven clean后,Maven install,直到控制台输出“BUILD SUCCESS”,到项目路径下的target文件夹中找到XXX-0.0.1-SNAPSHOT.war的包,改名简短写,复制到服务器Tomcat目录的webapps文件夹中。
标签:static api Servle enc 控制台 tomcat etc builder java
原文地址:https://www.cnblogs.com/lroy/p/12446097.html