[bs-124] Add tests for @ConditionalOnBean
[#49989537] [bs-124] @ConditionalOnBean doesn't work
This commit is contained in:
@@ -91,6 +91,7 @@ public class WebMvcAutoConfiguration {
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/**").addResourceLocations("/")
|
||||
.addResourceLocations("classpath:/META-INF/resources/")
|
||||
.addResourceLocations("classpath:/static")
|
||||
.addResourceLocations("classpath:/");
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.util.MultiValueMap;
|
||||
* Base for {@link OnBeanCondition} and {@link OnMissingBeanCondition}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Dave Syer
|
||||
*/
|
||||
abstract class AbstractOnBeanCondition implements Condition {
|
||||
|
||||
@@ -53,9 +54,6 @@ abstract class AbstractOnBeanCondition implements Condition {
|
||||
List<String> beanClassesFound = new ArrayList<String>();
|
||||
List<String> beanNamesFound = new ArrayList<String>();
|
||||
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Looking for beans with class: " + beanClasses);
|
||||
}
|
||||
for (String beanClass : beanClasses) {
|
||||
try {
|
||||
// eagerInit set to false to prevent early instantiation (some
|
||||
@@ -71,10 +69,6 @@ abstract class AbstractOnBeanCondition implements Condition {
|
||||
} catch (ClassNotFoundException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Looking for beans with names: " + beanNames);
|
||||
}
|
||||
for (String beanName : beanNames) {
|
||||
if (context.getBeanFactory().containsBeanDefinition(beanName)) {
|
||||
beanNamesFound.add(beanName);
|
||||
@@ -83,7 +77,16 @@ abstract class AbstractOnBeanCondition implements Condition {
|
||||
|
||||
boolean result = evaluate(beanClassesFound, beanNamesFound);
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Finished matching and result is matches: " + result);
|
||||
if (!beanClasses.isEmpty()) {
|
||||
this.logger.debug("Looking for beans with class: " + beanClasses);
|
||||
this.logger.debug("Found beans with classes: " + beanClassesFound);
|
||||
}
|
||||
|
||||
if (!beanNames.isEmpty()) {
|
||||
this.logger.debug("Looking for beans with names: " + beanNames);
|
||||
this.logger.debug("Found beans with names: " + beanNamesFound);
|
||||
}
|
||||
this.logger.debug("Match result is: " + result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class OnClassCondition implements Condition {
|
||||
}
|
||||
if (!ClassUtils.isPresent(className, context.getClassLoader())) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Found class: " + className
|
||||
logger.debug("Class not found: " + className
|
||||
+ " (search terminated with matches=false)");
|
||||
}
|
||||
return false;
|
||||
@@ -62,7 +62,7 @@ class OnClassCondition implements Condition {
|
||||
}
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Classes not found (search terminated with matches=true)");
|
||||
logger.debug("All classes found (search terminated with matches=true)");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user