SpringBoot去除内嵌tomcat的实现
程序员文章站
2022-07-02 20:14:56
springboot内嵌tomcat,直接run application即可,那么我们如何去除内嵌的tomcat,使用自己的呢?一、pom(去除内嵌tomcat后,需要添加servlet依赖) &...
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> </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方法
package com.example.export; 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.sources(this.getclass()); } }
三、添加到tomcat容器、run 即可
到此这篇关于springboot去除内嵌tomcat的实现的文章就介绍到这了,更多相关springboot去除内嵌tomcat内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: 亿联网云建站平台代理系统源码