如何基于SpringBoot部署外部Tomcat过程解析
作者:1024。 时间:2021-10-26 07:14:16
这篇文章主要介绍了SpringBoot以war包形式部署到外部Tomcat过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
SpringBoot 项目打包时能打成 .jar 与 .war包文件,.jar使用 java -jar xx.jar 就可以启动,而 .war 可以部署到tomcat的 webapps 中,随tomcat的启动而启动。
SpringBoot 本身是内置tomcat的,如果想部署到外部tomcat, 就要做一些改变。
1.在pom文件中将 packaging 改为war
1 <packaging>war</packaging>
2.在maven里排除springboot自带的tomcat
第一种
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions><!-- 移除嵌入式tomcat插件 -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
第二种
<!-- 如果使用第三方tomcat请增加scope -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
3.将项目的启动类Application.java继承SpringBootServletInitializer并重写configure方法
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(DemoApplication.class);
}
}
4.使用mvn clean package,或者编辑器打包成war包
来源:https://www.cnblogs.com/xhq1024/p/10649024.html
标签:Spring,Boot,war,部署,外部,Tomcat
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
springboot 通过代码自动生成pid的方法
2023-11-27 02:54:57
![](https://img.aspxhome.com/file/2023/6/60366_0s.png)
DecimalFormat多种用法详解
2022-11-13 15:06:52
java线程组构造方法源码解析
2022-11-24 08:58:26
![](https://img.aspxhome.com/file/2023/3/80273_0s.jpg)
C#使用XML序列化操作菜单的方法
2022-08-03 08:54:34
SpringBoot自定义加载yml实现方式,附源码解读
2022-01-22 22:39:40
![](https://img.aspxhome.com/file/2023/5/86025_0s.jpg)
C语言实现两个矩阵相乘
2023-07-22 12:41:20
![](https://img.aspxhome.com/file/2023/6/103076_0s.png)
hutool实战:IoUtil 流操作工具类(将内容写到流中)
2022-11-16 09:17:47
![](https://img.aspxhome.com/file/2023/6/83086_0s.png)
Android离线Doc文档访问速度慢的有效解决方法
2021-06-27 02:10:39
![](https://img.aspxhome.com/file/2023/2/104682_0s.png)
C#简单获取全屏中鼠标焦点位置坐标的方法示例
2023-09-14 16:18:04
java String校招面试题过程详解
2021-12-01 11:11:21
![](https://img.aspxhome.com/file/2023/1/95461_0s.png)
C#过滤DataTable中空数据和重复数据的示例代码
2022-03-15 19:33:45
Android 多媒体播放API简单实例
2022-12-12 18:53:24
![](https://img.aspxhome.com/file/2023/2/110742_0s.png)
Android编程常用技巧实例总结
2022-11-30 20:27:44
C# 禁用鼠标中间键的方法
2022-01-24 04:17:24
Java流程控制语句最全汇总(中篇)
2023-11-10 23:52:50
![](https://img.aspxhome.com/file/2023/9/58849_0s.jpg)
Spring BeanFactory和FactoryBean区别解析
2023-09-18 15:38:28
Java如何去掉指定字符串的开头的指定字符
2022-05-23 13:28:31
java中的SpringBoot框架
2022-02-10 16:50:05
Android垃圾回收机制解决内存泄露问题
2021-08-29 09:20:55
![](https://img.aspxhome.com/file/2023/2/97832_0s.png)
Java 中 hashCode() 与 equals() 的关系(面试)
2023-08-29 18:03:57