众所周知,springboot默认使用内置tomcat,但我们也可以使用外部tomcat。
1、环境约束
- win10 64位操作系统
- idea2018.1.5
- maven-3.0.5
- jdk-8u162-windows-x64
2、前提约束
- 完成springboot创建web项目 https://www.jianshu.com/p/de979f53ad80
注意,作者使用的springboot版本是2.1.8.RELEASE
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绑定外部容器的过程。
网友评论