码迷,mamicode.com
首页 > 编程语言 > 详细

Springboot项目部署到外置Tomcat

时间:2020-03-09 01:00:13      阅读:66      评论:0      收藏:0      [点我收藏+]

标签: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文件夹中。

 

Springboot项目部署到外置Tomcat

标签:static   api   Servle   enc   控制台   tomcat   etc   builder   java   

原文地址:https://www.cnblogs.com/lroy/p/12446097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!