springboot怎么关掉tomcat容器

springboot怎么关掉tomcat容器

这篇文章主要介绍“springboot怎么关掉tomcat容器”,在日常操作中,相信很多人在springboot怎么关掉tomcat容器问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”springboot怎么关掉tomcat容器”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

springboot关掉tomcat容器

有的时候需要对外提供的并不是HTTP服务,而是RPC服务,但是又想使用springboot提供的便利支持。

这个时候需要关掉RPC服务,然后在main函数中自己添加守护线程

public static void main(String[] args) {
  SpringApplication app = new SpringApplication(Application.class);
  app.setWebApplicationType(WebApplicationType.NONE);
  app.run(args);
 }

springboot使用第三方tomcat

1.改pom

因为代码用到了servlet的api,不加会报错。剔除web模块中的tomcat

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
		</dependency>
			
			 <!--添加servlet的依赖-->
	    <dependency>
	      <groupId>javax.servlet</groupId>
	      <artifactId>javax.servlet-api</artifactId>
	      <scope>provided</scope>
	    </dependency>

插件注释原先的springboot-maven插件,改为war

在warName 可以改名字,到时候打出的包名就是这个

		<plugins>
			<!-- <plugin>
		  		<groupId>org.springframework.boot</groupId>
		 		<artifactId>spring-boot-maven-plugin</artifactId>
		  	</plugin> -->
		  	
	  		<plugin>
			    <groupId>org.apache.maven.plugins</groupId>
			    <artifactId>maven-war-plugin</artifactId>
			    <configuration>
			        <warName>springboot</warName>
			    </configuration>
			</plugin>

改打包方式

	<packaging>war</packaging>

2.再加一个启动类

继承SpringBootServletInitializer 重写configure方法

@SpringBootApplication
@Configuration  
@ComponentScan(basePackages="com.jubao.dling")   //默认扫描是当前包下的路径
@EnableAutoConfiguration 
public class DlingApplication  extends SpringBootServletInitializer{ 
	public static void main(String[] args) {
		SpringApplication.run(DlingApplication.class, args);
	}	
	 @Override
	    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
	        return application.sources(DlingApplication.class);
	    } 
}

不必原来的启动类删除,因为 平常开发时,肯定还是使用内置的tomcat,开发时将 剔除tomcat的标签注释掉

3.打war包

放tomcat运行

springboot怎么关掉tomcat容器

到此,关于“springboot怎么关掉tomcat容器”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!