来自: org.springframework.boot.autoconfigure.condition.FilteringSpringBootCondition.ClassNameFilter
protected enum ClassNameFilter {
PRESENT {
@Override
public boolean matches(String className, ClassLoader classLoader) {
return isPresent(className, classLoader);
}
},
MISSING {
@Override
public boolean matches(String className, ClassLoader classLoader) {
return !isPresent(className, classLoader);
}
};
abstract boolean matches(String className, ClassLoader classLoader);
static boolean isPresent(String className, ClassLoader classLoader) {
if (classLoader == null) {
classLoader = ClassUtils.getDefaultClassLoader();
}
try {
resolve(className, classLoader);
return true;
}
catch (Throwable ex) {
return false;
}
}
}
SpringBoot自动配置中的ClassNameFilter枚举类解析
该代码段展示了SpringBoot自动配置中用于过滤条件的ClassNameFilter枚举。它包含两个枚举值:PRESENT和MISSING,分别检查类是否存在于类路径中。isPresent方法用于尝试加载并解析类,如果成功则表示类存在。
1019

被折叠的 条评论
为什么被折叠?



