springboot发布到独立的tomcat中运行

springboot发布到独立的tomcat中运行

  1. 将打包形式修改成war包

    <packaging>war</packaging>
  2. 将springboot的默认内嵌tomcat排除掉

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
  3. 修改项目启动方式
    写一个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);
    }
}

猜你喜欢

转载自blog.csdn.net/qq_29449785/article/details/78979570