springboot 设置web和非web启动

springBoot区分web和非web项目
老版本:


#server config
#web_environment是否是web项目
spring.main.web_environment=true
#是否加载springboot banner
spring.main.show_banner=false

现版本:

#server config
#是否设定web应用,none-非web,servlet-web应用
spring.main.web-application-type=servlet
#加载springboot banner的方式:off-关闭,console-控制台,log-日志
spring.main.banner-mode=off

WebApplicationType原理:

public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
    this.resourceLoader = resourceLoader;
    Assert.notNull(primarySources, "PrimarySources must not be null");
    this.primarySources = new LinkedHashSet<>(Arrays.asList(primarySources));
    this.webApplicationType = deduceWebApplicationType();
    setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));
    setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
    this.mainApplicationClass = deduceMainApplicationClass();
}

deduceWebApplicationType()推断当前环境是哪种Web环境(Servlet、Reactive),或者不是Web环境,判断逻辑为Classpath是够有以下类:
存在org.springframework.web.reactive.DispatcherHandler且不存在org.springframework.web.servlet.DispatcherServlet为WebApplicationType.REACTIVE;
同时存在javax.servlet.Servlet、org.springframework.web.context.ConfigurableWebApplicationContext 为WebApplicationType.SERVLET;
否则为 WebApplicationType.NONE
在这里this.webApplicationType = WebApplicationType.SERVLET;

所谓的banner就是控制台打印的一堆线组成的spring
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值