The Springboot project is deployed to the external Tomcat in the form of a war package

Step 1: Inherit SpringBootServletInitializer

If the external container is deployed, you can't rely on the main function of Application, but start the Spring application context in a way similar to the web.xml file configuration. At this time, we need to inherit SpringBootServletInitializer in the startup class and implement the configure method

package com.test.chaosblade;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

/**
 * @description:
 * @time: 2020-08-28 15:49
 */
@SpringBootApplication(exclude = {
    
     DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, SecurityAutoConfiguration.class })
public class ChaosbladeApplication extends SpringBootServletInitializer {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(ChaosbladeApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    
    
        return builder.sources(this.getClass());
        //此处的ChaosbladeApplication是springboot启动类
    }
}

Guess you like

Origin blog.csdn.net/sinat_34241861/article/details/115185968