码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot 发布到tomcat

时间:2019-08-13 09:18:45      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:prot   extend   void   stat   hub   tin   tap   repo   override   

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

spring boot 发布到tomcat

标签:prot   extend   void   stat   hub   tin   tap   repo   override   

原文地址:https://www.cnblogs.com/hanpengblog/p/11343586.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!