springboot不启动内置容器

springboot 2.4中,我们写的程序可能是一个服务,不需要提供http服务的,那么其实可以不用启动内置容器。若不想启动内置容器,需要将WebApplicationType设置为NONE ;有两种实现方式
一,在程序启动时指定

@RestController
@SpringBootApplication
public class Bootstrap {

    public static void main(String[] args) {
        System.setProperty("org.springframework.boot.logging.LoggingSystem", "org.springframework.boot.logging.log4j2.Log4J2LoggingSystem");

        SpringApplication application = new SpringApplication(Bootstrap.class);
        application.setWebApplicationType(WebApplicationType.NONE);
        application.run(args);

        //SpringApplication.run(Bootstrap.class, args);
    }

}

二,在配置中指定(applicaton.yml或application.properties)
参考官方网站文档 官方网站配置文档

spring:
  main:
    web-application-type: "none"

以上两种方式都可以不启动内置容器

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容