mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
[bs-73] Tweak configuration class detection algorithm some more
This looks like becoming a recurring theme. Unfortunately it's not very easy to test if a class might eventually be instantiatable by Spring. This change fixes the main bootstrap SpringApplicationTests which were failing because they used non-static inner classes for test configurations.
This commit is contained in:
parent
d6a670e13e
commit
4ca26058fa
|
@ -24,12 +24,14 @@ import org.springframework.beans.factory.support.BeanNameGenerator;
|
|||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
||||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter;
|
||||
import org.springframework.core.type.filter.TypeFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
@ -154,6 +156,11 @@ class BeanDefinitionLoader {
|
|||
}
|
||||
|
||||
private boolean isComponent(Class<?> type) {
|
||||
// This has to be a bit of a guess. The only way to be sure that this type is
|
||||
// eligible is to make a bean definition out of it and try to instantiate it.
|
||||
if (AnnotationUtils.findAnnotation(type, Component.class) != null) {
|
||||
return true;
|
||||
}
|
||||
// Nested anonymous classes are not eligible for registration, nor are groovy
|
||||
// closures
|
||||
if (type.isAnonymousClass() || type.getName().contains("$_closure")
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.springframework.beans.BeansException;
|
|||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||
import org.springframework.beans.factory.support.DefaultBeanNameGenerator;
|
||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
||||
import org.springframework.bootstrap.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
||||
import org.springframework.bootstrap.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
@ -331,7 +330,6 @@ public class SpringApplicationTests {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
static class ExampleWebConfig {
|
||||
|
||||
@Bean
|
||||
|
|
Loading…
Reference in New Issue
Block a user