springboot 配置外部容器 17

众所周知,springboot默认使用内置tomcat,但我们也可以使用外部tomcat。

1、环境约束

  • win10 64位操作系统
  • idea2018.1.5
  • maven-3.0.5
  • jdk-8u162-windows-x64

2、前提约束

3、操作步骤

  • 主启动类继承SpringBootServletInitializer,并重写configure方法
public class SpringbootDemoApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringbootDemoApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(SpringbootDemoApplication.class, args);
    }
  • 在pom.xml中加入:
    <packaging>war</packaging>
  • 在pom.xml中加入依赖:
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
  • clean->install->绑定tomcat->启动即可。
    以上就是springboot绑定外部容器的过程。
posted @ 2020-04-06 20:13  张力的程序园  阅读(435)  评论(0)    收藏  举报