博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot2 源码学习笔记(三)
阅读量:2353 次
发布时间:2019-05-10

本文共 1336 字,大约阅读时间需要 4 分钟。

创建哪种web应用类型是怎么决定的

首先看看返回web应用类型的方法,我们可以看到这个类并没有传入任何变量,包括执行的时候也没有依赖外部的变量,那么它是怎么决定采用哪种应用类型的呢?

private WebApplicationType deduceWebApplicationType() {		if (ClassUtils.isPresent(REACTIVE_WEB_ENVIRONMENT_CLASS, null)				&& !ClassUtils.isPresent(MVC_WEB_ENVIRONMENT_CLASS, null)) {			return WebApplicationType.REACTIVE;		}		for (String className : WEB_ENVIRONMENT_CLASSES) {			if (!ClassUtils.isPresent(className, null)) {				return WebApplicationType.NONE;			}		}		return WebApplicationType.SERVLET;	}

 

我们进入 ClassUtils.isPresent 方法。我们可以看到这个方法的主要作用是通过反射判断相应的类存不存在。

所以,我猜测 SpringBoot 通过我们引入的 jar 来帮助我们自动配置相应的 web 应用类型,当然,如果我们同时引入了多个相关的jar包,那么则根据优先级来设定究竟需要哪一个。

/**	 * Determine whether the {@link Class} identified by the supplied name is present	 * and can be loaded. Will return {@code false} if either the class or	 * one of its dependencies is not present or cannot be loaded.	 * @param className the name of the class to check	 * @param classLoader the class loader to use	 * (may be {@code null} which indicates the default class loader)	 * @return whether the specified class is present	 */	public static boolean isPresent(String className, @Nullable ClassLoader classLoader) {		try {			forName(className, classLoader);			return true;		}		catch (Throwable ex) {			// Class or one of its dependencies is not present...			return false;		}	}

 

转载地址:http://okwtb.baihongyu.com/

你可能感兴趣的文章
在Fragment中OnActivityResult方法中接收Activity中返回的值
查看>>
外包采用Gradle生成多套app打包
查看>>
iOS和Android的app界面设计规范
查看>>
Android 代码混淆异常
查看>>
Android drawable微技巧,你所不知道的drawable的那些细节
查看>>
理解Fragment生命周期
查看>>
最靠谱的禁止ViewPager滑动方法
查看>>
android错误之android.content.res.Resources$NotFoundException:
查看>>
Android监听软键盘打开收起事件(软键盘自带收起按钮)
查看>>
huffman code and encode
查看>>
exception in c++
查看>>
java并发编程lock
查看>>
阿里云技术教程系列-ECS远程连接 Linux 实例
查看>>
Linux新建用户并允许docker
查看>>
Drools Workbench 7.5.0.Final安装运行
查看>>
Docker快速部署Redis
查看>>
Spring boot shiro session cache ecache redis 共存配置
查看>>
一看就懂的设计模式--设计模式分类
查看>>
一看就懂的设计模式--模板方法
查看>>
一看就懂的设计模式--享元模式
查看>>