SpringBoot內(nèi)部提供了特有的注解:條件注解(Conditional Annotation)。比如@ConditionalOnBean朗鸠、@ConditionalOnClass晋控、@ConditionalOnExpression崔挖、@ConditionalOnMissingBean等矢渊。
條件注解存在的意義在于動(dòng)態(tài)識別(也可以說是代碼自動(dòng)化執(zhí)行)战转。比如@ConditionalOnClass會(huì)檢查類加載器中是否存在對應(yīng)的類,如果有的話被注解修飾的類就有資格被Spring容器所注冊予弧,否則會(huì)被skip刮吧。
比如FreemarkerAutoConfiguration這個(gè)自動(dòng)化配置類的定義如下:
@Configuration
@ConditionalOnClass({ freemarker.template.Configuration.class,
FreeMarkerConfigurationFactory.class })
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
@EnableConfigurationProperties(FreeMarkerProperties.class)
public class FreeMarkerAutoConfiguration
這個(gè)自動(dòng)化配置類被@ConditionalOnClass條件注解修飾,這個(gè)條件注解存在的意義在于判斷類加載器中是否存在freemarker.template.Configuration和FreeMarkerConfigurationFactory這兩個(gè)類掖蛤,如果都存在的話會(huì)在Spring容器中加載這個(gè)FreeMarkerAutoConfiguration配置類杀捻;否則不會(huì)加載。
條件注解內(nèi)部的一些基礎(chǔ)
在分析條件注解的底層實(shí)現(xiàn)之前蚓庭,我們先來看一下這些條件注解的定義致讥。以@ConditionalOnClass注解為例,它的定義如下:
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnClassCondition.class)
public @interface ConditionalOnClass {
Class<?>[] value() default {}; // 需要匹配的類
String[] name() default {}; // 需要匹配的類名
}
它有2個(gè)屬性器赞,分別是類數(shù)組和字符串?dāng)?shù)組(作用一樣垢袱,類型不一樣),而且被@Conditional注解所修飾港柜,這個(gè)@Conditional注解有個(gè)名為values的Class<? extends Condition>[]類型的屬性请契。 這個(gè)Condition是個(gè)接口,用于匹配組件是否有資格被容器注冊潘懊,定義如下:
public interface Condition {
// ConditionContext內(nèi)部會(huì)存儲Spring容器姚糊、應(yīng)用程序環(huán)境信息、資源加載器授舟、類加載器
boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata);
}
也就是說@Conditional注解屬性中可以持有多個(gè)Condition接口的實(shí)現(xiàn)類救恨,所有的Condition接口需要全部匹配成功后這個(gè)@Conditional修飾的組件才有資格被注冊。
Condition接口有個(gè)子接口ConfigurationCondition:
public interface ConfigurationCondition extends Condition {
ConfigurationPhase getConfigurationPhase();
public static enum ConfigurationPhase {
PARSE_CONFIGURATION,
REGISTER_BEAN
}
}
這個(gè)子接口是一種特殊的條件接口释树,多了一個(gè)getConfigurationPhase方法肠槽,也就是條件注解的生效階段。只有在ConfigurationPhase中定義的兩種階段下才會(huì)生效奢啥。
Condition接口有個(gè)實(shí)現(xiàn)抽象類SpringBootCondition秸仙,SpringBoot中所有條件注解對應(yīng)的條件類都繼承這個(gè)抽象類。它實(shí)現(xiàn)了matches方法:
@Override
public final boolean matches(ConditionContext context,
AnnotatedTypeMetadata metadata) {
String classOrMethodName = getClassOrMethodName(metadata); // 得到類名或者方法名(條件注解可以作用的類或者方法上)
try {
ConditionOutcome outcome = getMatchOutcome(context, metadata); // 抽象方法桩盲,具體子類實(shí)現(xiàn)寂纪。ConditionOutcome記錄了匹配結(jié)果boolean和log信息
logOutcome(classOrMethodName, outcome); // log記錄一下匹配信息
recordEvaluation(context, classOrMethodName, outcome); // 報(bào)告記錄一下匹配信息
return outcome.isMatch(); // 返回是否匹配
}
catch (NoClassDefFoundError ex) {
throw new IllegalStateException(
"Could not evaluate condition on " + classOrMethodName + " due to "
+ ex.getMessage() + " not "
+ "found. Make sure your own configuration does not rely on "
+ "that class. This can also happen if you are "
+ "@ComponentScanning a springframework package (e.g. if you "
+ "put a @ComponentScan in the default package by mistake)",
ex);
}
catch (RuntimeException ex) {
throw new IllegalStateException(
"Error processing condition on " + getName(metadata), ex);
}
}
基于Class的條件注解
SpringBoot提供了兩個(gè)基于Class的條件注解:@ConditionalOnClass(類加載器中存在指明的類)或者@ConditionalOnMissingClass(類加載器中不存在指明的類)。
@ConditionalOnClass或者@ConditionalOnMissingClass注解對應(yīng)的條件類是OnClassCondition赌结,定義如下:
@Order(Ordered.HIGHEST_PRECEDENCE) // 優(yōu)先級捞蛋、最高級別
class OnClassCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
StringBuffer matchMessage = new StringBuffer(); // 記錄匹配信息
MultiValueMap<String, Object> onClasses = getAttributes(metadata,
ConditionalOnClass.class); // 得到@ConditionalOnClass注解的屬性
if (onClasses != null) { // 如果屬性存在
List<String> missing = getMatchingClasses(onClasses, MatchType.MISSING,
context); // 得到在類加載器中不存在的類
if (!missing.isEmpty()) { // 如果存在類加載器中不存在對應(yīng)的類,返回一個(gè)匹配失敗的ConditionalOutcome
return ConditionOutcome
.noMatch("required @ConditionalOnClass classes not found: "
+ StringUtils.collectionToCommaDelimitedString(missing));
}
// 如果類加載器中存在對應(yīng)的類的話柬姚,匹配信息進(jìn)行記錄
matchMessage.append("@ConditionalOnClass classes found: "
+ StringUtils.collectionToCommaDelimitedString(
getMatchingClasses(onClasses, MatchType.PRESENT, context)));
}
// 對@ConditionalOnMissingClass注解做相同的邏輯處理(說明@ConditionalOnClass和@ConditionalOnMissingClass可以一起使用)
MultiValueMap<String, Object> onMissingClasses = getAttributes(metadata,
ConditionalOnMissingClass.class);
if (onMissingClasses != null) {
List<String> present = getMatchingClasses(onMissingClasses, MatchType.PRESENT,
context);
if (!present.isEmpty()) {
return ConditionOutcome
.noMatch("required @ConditionalOnMissing classes found: "
+ StringUtils.collectionToCommaDelimitedString(present));
}
matchMessage.append(matchMessage.length() == 0 ? "" : " ");
matchMessage.append("@ConditionalOnMissing classes not found: "
+ StringUtils.collectionToCommaDelimitedString(getMatchingClasses(
onMissingClasses, MatchType.MISSING, context)));
}
// 返回全部匹配成功的ConditionalOutcome
return ConditionOutcome.match(matchMessage.toString());
}
private enum MatchType { // 枚舉:匹配類型拟杉。用于查詢類名在對應(yīng)的類加載器中是否存在。
PRESENT { // 匹配成功
@Override
public boolean matches(String className, ConditionContext context) {
return ClassUtils.isPresent(className, context.getClassLoader());
}
},
MISSING { // 匹配不成功
@Override
public boolean matches(String className, ConditionContext context) {
return !ClassUtils.isPresent(className, context.getClassLoader());
}
};
public abstract boolean matches(String className, ConditionContext context);
}
}
比如FreemarkerAutoConfiguration中的@ConditionalOnClass注解中有value屬性是freemarker.template.Configuration.class和FreeMarkerConfigurationFactory.class量承。在OnClassCondition執(zhí)行過程中得到的最終ConditionalOutcome中的log message如下:
@ConditionalOnClass classes found: freemarker.template.Configuration,org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
基于Bean的條件注解
@ConditionalOnBean(Spring容器中存在指明的bean)搬设、@ConditionalOnMissingBean(Spring容器中不存在指明的bean)以及ConditionalOnSingleCandidate(Spring容器中存在且只存在一個(gè)指明的bean)都是基于Bean的條件注解穴店,它們對應(yīng)的條件類是ConditionOnBean。
@ConditionOnBean注解定義如下:
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnBeanCondition.class)
public @interface ConditionalOnBean {
Class<?>[] value() default {}; // 匹配的bean類型
String[] type() default {}; // 匹配的bean類型的類名
Class<? extends Annotation>[] annotation() default {}; // 匹配的bean注解
String[] name() default {}; // 匹配的bean的名字
SearchStrategy search() default SearchStrategy.ALL; // 搜索策略拿穴。提供CURRENT(只在當(dāng)前容器中找)泣洞、PARENTS(只在所有的父容器中找;但是不包括當(dāng)前容器)和ALL(CURRENT和PARENTS的組合)
}
OnBeanCondition條件類的匹配代碼如下:
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
StringBuffer matchMessage = new StringBuffer(); // 記錄匹配信息
if (metadata.isAnnotated(ConditionalOnBean.class.getName())) {
BeanSearchSpec spec = new BeanSearchSpec(context, metadata,
ConditionalOnBean.class); // 構(gòu)造一個(gè)BeanSearchSpec默色,會(huì)從@ConditionalOnBean注解中獲取屬性斜棚,然后設(shè)置到BeanSearchSpec中
List<String> matching = getMatchingBeans(context, spec); // 從BeanFactory中根據(jù)策略找出所有匹配的bean
if (matching.isEmpty()) { // 如果沒有匹配的bean,返回一個(gè)沒有匹配成功的ConditionalOutcome
return ConditionOutcome
.noMatch("@ConditionalOnBean " + spec + " found no beans");
}
// 如果找到匹配的bean该窗,匹配信息進(jìn)行記錄
matchMessage.append(
"@ConditionalOnBean " + spec + " found the following " + matching);
}
if (metadata.isAnnotated(ConditionalOnSingleCandidate.class.getName())) { // 相同的邏輯弟蚀,針對@ConditionalOnSingleCandidate注解
BeanSearchSpec spec = new SingleCandidateBeanSearchSpec(context, metadata,
ConditionalOnSingleCandidate.class);
List<String> matching = getMatchingBeans(context, spec);
if (matching.isEmpty()) {
return ConditionOutcome.noMatch(
"@ConditionalOnSingleCandidate " + spec + " found no beans");
}
else if (!hasSingleAutowireCandidate(context.getBeanFactory(), matching)) { // 多了一層判斷,判斷是否只有一個(gè)bean
return ConditionOutcome.noMatch("@ConditionalOnSingleCandidate " + spec
+ " found no primary candidate amongst the" + " following "
+ matching);
}
matchMessage.append("@ConditionalOnSingleCandidate " + spec + " found "
+ "a primary candidate amongst the following " + matching);
}
if (metadata.isAnnotated(ConditionalOnMissingBean.class.getName())) { // 相同的邏輯酗失,針對@ConditionalOnMissingBean注解
BeanSearchSpec spec = new BeanSearchSpec(context, metadata,
ConditionalOnMissingBean.class);
List<String> matching = getMatchingBeans(context, spec);
if (!matching.isEmpty()) {
return ConditionOutcome.noMatch("@ConditionalOnMissingBean " + spec
+ " found the following " + matching);
}
matchMessage.append(matchMessage.length() == 0 ? "" : " ");
matchMessage.append("@ConditionalOnMissingBean " + spec + " found no beans");
}
return ConditionOutcome.match(matchMessage.toString()); //返回匹配成功的ConditonalOutcome
}
SpringBoot還提供了其他比如ConditionalOnJava义钉、ConditionalOnNotWebApplication、ConditionalOnWebApplication规肴、ConditionalOnResource捶闸、ConditionalOnProperty、ConditionalOnExpression等條件注解拖刃,有興趣的讀者可以自行查看它們的底層處理邏輯删壮。
各種條件注解的總結(jié)
條件注解 | 對應(yīng)的Condition處理類 | 處理邏輯 |
---|---|---|
@ConditionalOnBean | OnBeanCondition | Spring容器中是否存在對應(yīng)的實(shí)例《夷担可以通過實(shí)例的類型央碟、類名、注解均函、昵稱去容器中查找(可以配置從當(dāng)前容器中查找或者父容器中查找或者兩者一起查找)這些屬性都是數(shù)組亿虽,通過"與"的關(guān)系進(jìn)行查找 |
@ConditionalOnClass | OnClassCondition | 類加載器中是否存在對應(yīng)的類“玻可以通過Class指定(value屬性)或者Class的全名指定(name屬性)洛勉。如果是多個(gè)類或者多個(gè)類名的話,關(guān)系是"與"關(guān)系如迟,也就是說這些類或者類名都必須同時(shí)在類加載器中存在 |
@ConditionalOnExpression | OnExpressionCondition | 判斷SpEL 表達(dá)式是否成立 |
@ConditionalOnJava | OnJavaCondition | 指定Java版本是否符合要求收毫。內(nèi)部有2個(gè)屬性value和range。value表示一個(gè)枚舉的Java版本殷勘,range表示比這個(gè)老或者新于等于指定的Java版本(默認(rèn)是新于等于)此再。內(nèi)部會(huì)基于某些jdk版本特有的類去類加載器中查詢,比如如果是jdk9劳吠,類加載器中需要存在java.security.cert.URICertStoreParameters引润;如果是jdk8巩趁,類加載器中需要存在java.util.function.Function痒玩;如果是jdk7淳附,類加載器中需要存在java.nio.file.Files;如果是jdk6蠢古,類加載器中需要存在java.util.ServiceLoader |
@ConditionalOnMissingBean | OnBeanCondition | Spring容器中是否缺少對應(yīng)的實(shí)例奴曙。可以通過實(shí)例的類型草讶、類名洽糟、注解、昵稱去容器中查找(可以配置從當(dāng)前容器中查找或者父容器中查找或者兩者一起查找)這些屬性都是數(shù)組堕战,通過"與"的關(guān)系進(jìn)行查找坤溃。還多了2個(gè)屬性ignored(類名)和ignoredType(類名),匹配的過程中會(huì)忽略這些bean |
@ConditionalOnMissingClass | OnClassCondition | 跟ConditionalOnClass的處理邏輯一樣嘱丢,只是條件相反薪介,在類加載器中不存在對應(yīng)的類 |
@ConditionalOnNotWebApplication | OnWebApplicationCondition | 應(yīng)用程序是否是非Web程序,沒有提供屬性越驻,只是一個(gè)標(biāo)識汁政。會(huì)從判斷Web程序特有的類是否存在,環(huán)境是否是Servlet環(huán)境缀旁,容器是否是Web容器等 |
@ConditionalOnProperty | OnPropertyCondition | 應(yīng)用環(huán)境中的屬性是否存在记劈。提供prefix、name并巍、havingValue以及matchIfMissing屬性目木。prefix表示屬性名的前綴,name是屬性名懊渡,havingValue是具體的屬性值嘶窄,matchIfMissing是個(gè)boolean值,如果屬性不存在距贷,這個(gè)matchIfMissing為true的話柄冲,會(huì)繼續(xù)驗(yàn)證下去,否則屬性不存在的話直接就相當(dāng)于匹配不成功 |
@ConditionalOnResource | OnResourceCondition | 是否存在指定的資源文件忠蝗。只有一個(gè)屬性resources现横,是個(gè)String數(shù)組。會(huì)從類加載器中去查詢對應(yīng)的資源文件是否存在 |
@ConditionalOnSingleCandidate | OnBeanCondition | Spring容器中是否存在且只存在一個(gè)對應(yīng)的實(shí)例阁最。只有3個(gè)屬性value戒祠、type、search速种。跟ConditionalOnBean中的這3種屬性值意義一樣 |
@ConditionalOnWebApplication | OnWebApplicationCondition | 應(yīng)用程序是否是Web程序姜盈,沒有提供屬性,只是一個(gè)標(biāo)識配阵。會(huì)從判斷Web程序特有的類是否存在馏颂,環(huán)境是否是Servlet環(huán)境示血,容器是否是Web容器等 |
例子 | 例子意義 |
---|---|
@ConditionalOnBean(javax.sql.DataSource.class) | Spring容器或者所有父容器中需要存在至少一個(gè)javax.sql.DataSource類的實(shí)例 |
@ConditionalOnClass ({ Configuration.class, FreeMarkerConfigurationFactory.class }) |
類加載器中必須存在Configuration和FreeMarkerConfigurationFactory這兩個(gè)類 |
@ConditionalOnExpression ("'${server.host}'=='localhost'") |
server.host配置項(xiàng)的值需要是localhost |
ConditionalOnJava(JavaVersion.EIGHT) | Java版本至少是8 |
@ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT) | Spring當(dāng)前容器中不存在ErrorController類型的bean |
@ConditionalOnMissingClass ("GenericObjectPool") |
類加載器中不能存在GenericObjectPool這個(gè)類 |
@ConditionalOnNotWebApplication | 必須在非Web應(yīng)用下才會(huì)生效 |
@ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true) | 應(yīng)用程序的環(huán)境中必須有spring.aop.auto這項(xiàng)配置,且它的值是true或者環(huán)境中不存在spring.aop.auto配置(matchIfMissing為true) |
@ConditionalOnResource (resources="mybatis.xml") |
類加載路徑中必須存在mybatis.xml文件 |
@ConditionalOnSingleCandidate (PlatformTransactionManager.class) |
Spring當(dāng)前或父容器中必須存在PlatformTransactionManager這個(gè)類型的實(shí)例救拉,且只有一個(gè)實(shí)例 |
@ConditionalOnWebApplication | 必須在Web應(yīng)用下才會(huì)生效 |
SpringBoot條件注解的激活機(jī)制
分析完了條件注解的執(zhí)行邏輯之后难审,接下來的問題就是SpringBoot是如何讓這些條件注解生效的?
SpringBoot使用ConditionEvaluator這個(gè)內(nèi)部類完成條件注解的解析和判斷亿絮。
在Spring容器的refresh過程中告喊,只有跟解析或者注冊bean有關(guān)系的類都會(huì)使用ConditionEvaluator完成條件注解的判斷,這個(gè)過程中一些類不滿足條件的話就會(huì)被skip派昧。這些類比如有AnnotatedBeanDefinitionReader黔姜、ConfigurationClassBeanDefinitionReader、ConfigurationClassParse蒂萎、ClassPathScanningCandidateComponentProvider等地淀。
比如ConfigurationClassParser的構(gòu)造函數(shù)會(huì)初始化內(nèi)部屬性conditionEvaluator:
public ConfigurationClassParser(MetadataReaderFactory metadataReaderFactory,
ProblemReporter problemReporter, Environment environment, ResourceLoader resourceLoader,
BeanNameGenerator componentScanBeanNameGenerator, BeanDefinitionRegistry registry) {
this.metadataReaderFactory = metadataReaderFactory;
this.problemReporter = problemReporter;
this.environment = environment;
this.resourceLoader = resourceLoader;
this.registry = registry;
this.componentScanParser = new ComponentScanAnnotationParser(
resourceLoader, environment, componentScanBeanNameGenerator, registry);
// 構(gòu)造ConditionEvaluator用于處理?xiàng)l件注解
this.conditionEvaluator = new ConditionEvaluator(registry, environment, resourceLoader);
}
ConfigurationClassParser對每個(gè)配置類進(jìn)行解析的時(shí)候都會(huì)使用ConditionEvaluator:
if (this.conditionEvaluator.shouldSkip(configClass.getMetadata(), ConfigurationPhase.PARSE_CONFIGURATION)) {
return;
}
ConditionEvaluator的skip方法:
public boolean shouldSkip(AnnotatedTypeMetadata metadata, ConfigurationPhase phase) {
// 如果這個(gè)類沒有被@Conditional注解所修飾,不會(huì)skip
if (metadata == null || !metadata.isAnnotated(Conditional.class.getName())) {
return false;
}
// 如果參數(shù)中沒有設(shè)置條件注解的生效階段
if (phase == null) {
// 是配置類的話直接使用PARSE_CONFIGURATION階段
if (metadata instanceof AnnotationMetadata &&
ConfigurationClassUtils.isConfigurationCandidate((AnnotationMetadata) metadata)) {
return shouldSkip(metadata, ConfigurationPhase.PARSE_CONFIGURATION);
}
// 否則使用REGISTER_BEAN階段
return shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN);
}
// 要解析的配置類的條件集合
List<Condition> conditions = new ArrayList<Condition>();
// 獲取配置類的條件注解得到條件數(shù)據(jù)岖是,并添加到集合中
for (String[] conditionClasses : getConditionClasses(metadata)) {
for (String conditionClass : conditionClasses) {
Condition condition = getCondition(conditionClass, this.context.getClassLoader());
conditions.add(condition);
}
}
// 對條件集合做個(gè)排序
AnnotationAwareOrderComparator.sort(conditions);
// 遍歷條件集合
for (Condition condition : conditions) {
ConfigurationPhase requiredPhase = null;
if (condition instanceof ConfigurationCondition) {
requiredPhase = ((ConfigurationCondition) condition).getConfigurationPhase();
}
// 沒有這個(gè)解析類不需要階段的判斷或者解析類和參數(shù)中的階段一致才會(huì)繼續(xù)進(jìn)行
if (requiredPhase == null || requiredPhase == phase) {
// 階段一致切不滿足條件的話帮毁,返回true并跳過這個(gè)bean的解析
if (!condition.matches(this.context, metadata)) {
return true;
}
}
}
return false;
}
SpringBoot在條件注解的解析log記錄在了ConditionEvaluationReport類中,可以通過BeanFactory獲取(BeanFactory是有父子關(guān)系的豺撑;每個(gè)BeanFactory都存有一份ConditionEvaluationReport烈疚,互不相干):
ConditionEvaluationReport conditionEvaluationReport = beanFactory.getBean("autoConfigurationReport", ConditionEvaluationReport.class);
Map<String, ConditionEvaluationReport.ConditionAndOutcomes> result = conditionEvaluationReport.getConditionAndOutcomesBySource();
for(String key : result.keySet()) {
ConditionEvaluationReport.ConditionAndOutcomes conditionAndOutcomes = result.get(key);
Iterator<ConditionEvaluationReport.ConditionAndOutcome> iterator = conditionAndOutcomes.iterator();
while(iterator.hasNext()) {
ConditionEvaluationReport.ConditionAndOutcome conditionAndOutcome = iterator.next();
System.out.println(key + " -- " + conditionAndOutcome.getCondition().getClass().getSimpleName() + " -- " + conditionAndOutcome.getOutcome());
}
}
打印出條件注解下的類加載信息:
.......
org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration -- OnClassCondition -- required @ConditionalOnClass classes not found: freemarker.template.Configuration,org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration -- OnClassCondition -- required @ConditionalOnClass classes not found: groovy.text.markup.MarkupTemplateEngine
org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration -- OnClassCondition -- required @ConditionalOnClass classes not found: com.google.gson.Gson
org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration -- OnClassCondition -- required @ConditionalOnClass classes not found: org.h2.server.web.WebServlet
org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration -- OnClassCondition -- required @ConditionalOnClass classes not found: org.springframework.hateoas.Resource,org.springframework.plugin.core.Plugin
org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration -- OnClassCondition -- required @ConditionalOnClass classes not found: com.hazelcast.core.HazelcastInstance
.......
一些測試的例子代碼在 https://github.com/fangjian0423/springboot-analysis/tree/master/springboot-conditional 上