6.Spring-Boot项目发布到独立的tomcat中

本文介绍如何将Spring Boot应用从内嵌Tomcat部署转换为独立Tomcat容器部署的方法,包括调整Maven打包方式和配置启动类等步骤。

在开发阶段我们推荐使用内嵌的tomcat进行开发,因为这样会方便很多,但是到生成环境,我希望在独立的tomcat容器中运行,因为我们需要对tomcat做额外的优化,这时我们需要将工程打包成war包发进行发布。

1.将spring-boot-starter-tomcat的范围设置为provided

1、maven项目,修改pom包

  1. <packaging>jar</packaging>  

改为

  1. <packaging>war</packaging>

 

设置为provided是在打包时会将该包排除,因为要放到独立的tomcat中运行,是不需要的。

<dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-tomcat</artifactId>

        <scope>provided</scope>

      </dependency>

2.修改代码,设置启动配置

需要集成SpringBootServletInitializer,然后重写configure,将Spring Boot的入口类设置进去。

public class Application extends SpringBootServletInitializer {

public static void main(String[] args) {

SpringApplication.run(Application.class, args);

}

}

                                                                       微信公众号: 

                                               

                                                                             JAVA程序猿成长之路

                          分享资源,记录程序猿成长点滴。专注于Java,Spring,SpringBoot,SpringCloud,分布式,微服务。 

[INFO] +- org.springframework.boot:spring-boot-starter-websocket:jar:2.2.5.RELEASE:compile [INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.5.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.2.5.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.5.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.5.RELEASE:compile [INFO] +- org.springframework.boot:spring-boot-starter:jar:2.2.5.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot:jar:2.2.5.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.5.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.5.RELEASE:compile [INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.2.5.RELEASE:compile (optional) [INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.2.5.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:2.2.5.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.2.5.RELEASE:compile [INFO] +- org.springframework.boot:spring-boot-starter-data-redis:jar:2.2.5.RELEASE:compile [INFO] +- com.alibaba:druid-spring-boot-starter:jar:1.2.8:compile [INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.2.5.RELEASE:test [INFO] | +- org.springframework.boot:spring-boot-test:jar:2.2.5.RELEASE:test [INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.2.5.RELEASE:test
最新发布
03-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值