springboot发布到独立的tomcat中
springboot发布到独立的tomcat中运行
-
将打包形式修改成war包
<packaging>war</packaging> -
将springboot的默认内嵌tomcat排除掉
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> -
修改项目启动方式
写一个SpringBootServletInitializer 子类,并覆盖它的 configure 方法,这个子类可以是应用的主类,也可以另外写一个类
package com.test; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.support.SpringBootServletInitializer; @SpringBootApplication public class MyApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(MyApplication .class); } public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }
公众号?“码农神站”走起!
本文来自博客园,作者:码上猎人,转载请注明原文链接:https://www.cnblogs.com/xyddm/p/9141408.html

浙公网安备 33010602011771号