SpringBoot去除内嵌tomcat的实现
SpringBoot内嵌tomcat,直接run Application即可,那么我们如何去除内嵌的tomcat,使⽤⾃⼰的呢?
⼀、POM(去除内嵌tomcat后,需要添加servlet依赖)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 去除内嵌tomcat -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
springframework和springboot</dependency>
<!--添加servlet的依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
</plugin>
打包⽅式设置成war
<packaging>war</packaging>
⼆、继承SpringBootServletInitializer重写configure⽅法
port;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class ExportApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ExportApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.Class());
}
}
三、添加到tomcat容器、run 即可
到此这篇关于SpringBoot去除内嵌tomcat的实现的⽂章就介绍到这了,更多相关SpringBoot去除内嵌tomcat内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。