spring boot 发布到tomcat

1、pom.xml 中增加

<!-- 打包到tomcat 1-->
<packaging>war</packaging>

 

移除spring boot 中的tomcat

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <!-- 打包到tomcat 2-->
        <exclusion>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

 

添加依赖

<!-- 打包到tomcat 3-->
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>

 

2、启动类修改:

//<!-- 打包到tomcat 4-->
//集成 SpringBootServletInitializer 并重写 configure

@Import({DataSourceConfig.class, MyBatisDbClickHouseConfig.class, MyBatisDbOracleConfig.class})
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class Application extends SpringBootServletInitializer {
@Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

 

具体详情想看源码,地址:https://github.com/hanpenggit/multiDataSourcedemo-mybatis

posted @ 2019-08-13 06:54  车祸现场  阅读(187)  评论(0编辑  收藏  举报