|
|
|
@ -147,7 +147,7 @@ public class ComponentScanAnnotationIntegrationTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void withCustomBeanNameGenerator() { |
|
|
|
public void withCustomBeanNameGenerator() { |
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
|
|
|
ctx.register(ComponentScanWithBeanNameGenenerator.class); |
|
|
|
ctx.register(ComponentScanWithBeanNameGenerator.class); |
|
|
|
ctx.refresh(); |
|
|
|
ctx.refresh(); |
|
|
|
assertThat(ctx.containsBean("custom_fooServiceImpl"), is(true)); |
|
|
|
assertThat(ctx.containsBean("custom_fooServiceImpl"), is(true)); |
|
|
|
assertThat(ctx.containsBean("fooServiceImpl"), is(false)); |
|
|
|
assertThat(ctx.containsBean("fooServiceImpl"), is(false)); |
|
|
|
@ -241,7 +241,8 @@ public class ComponentScanAnnotationIntegrationTests { |
|
|
|
@ComponentScan |
|
|
|
@ComponentScan |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Target(ElementType.TYPE) |
|
|
|
@Target(ElementType.TYPE) |
|
|
|
public static @interface ComposedConfiguration { |
|
|
|
public @interface ComposedConfiguration { |
|
|
|
|
|
|
|
|
|
|
|
String[] basePackages() default {}; |
|
|
|
String[] basePackages() default {}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -253,8 +254,9 @@ public class ComponentScanAnnotationIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan(basePackageClasses=example.scannable._package.class) |
|
|
|
@ComponentScan(basePackageClasses = example.scannable._package.class) |
|
|
|
class ComponentScanAnnotatedConfig { |
|
|
|
class ComponentScanAnnotatedConfig { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public TestBean testBean() { |
|
|
|
public TestBean testBean() { |
|
|
|
return new TestBean(); |
|
|
|
return new TestBean(); |
|
|
|
@ -264,6 +266,7 @@ class ComponentScanAnnotatedConfig { |
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan("example.scannable") |
|
|
|
@ComponentScan("example.scannable") |
|
|
|
class ComponentScanAnnotatedConfig_WithValueAttribute { |
|
|
|
class ComponentScanAnnotatedConfig_WithValueAttribute { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
public TestBean testBean() { |
|
|
|
public TestBean testBean() { |
|
|
|
return new TestBean(); |
|
|
|
return new TestBean(); |
|
|
|
@ -272,13 +275,16 @@ class ComponentScanAnnotatedConfig_WithValueAttribute { |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan |
|
|
|
@ComponentScan |
|
|
|
class ComponentScanWithNoPackagesConfig {} |
|
|
|
class ComponentScanWithNoPackagesConfig { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan(basePackages="example.scannable", nameGenerator=MyBeanNameGenerator.class) |
|
|
|
@ComponentScan(basePackages = "example.scannable", nameGenerator = MyBeanNameGenerator.class) |
|
|
|
class ComponentScanWithBeanNameGenenerator {} |
|
|
|
class ComponentScanWithBeanNameGenerator { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MyBeanNameGenerator extends AnnotationBeanNameGenerator { |
|
|
|
class MyBeanNameGenerator extends AnnotationBeanNameGenerator { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) { |
|
|
|
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) { |
|
|
|
return "custom_" + super.generateBeanName(definition, registry); |
|
|
|
return "custom_" + super.generateBeanName(definition, registry); |
|
|
|
@ -286,10 +292,12 @@ class MyBeanNameGenerator extends AnnotationBeanNameGenerator { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan(basePackages="example.scannable_scoped", scopeResolver=MyScopeMetadataResolver.class) |
|
|
|
@ComponentScan(basePackages = "example.scannable_scoped", scopeResolver = MyScopeMetadataResolver.class) |
|
|
|
class ComponentScanWithScopeResolver {} |
|
|
|
class ComponentScanWithScopeResolver { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class MyScopeMetadataResolver extends AnnotationScopeMetadataResolver { |
|
|
|
class MyScopeMetadataResolver extends AnnotationScopeMetadataResolver { |
|
|
|
|
|
|
|
|
|
|
|
MyScopeMetadataResolver() { |
|
|
|
MyScopeMetadataResolver() { |
|
|
|
this.scopeAnnotationType = MyScope.class; |
|
|
|
this.scopeAnnotationType = MyScope.class; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -297,13 +305,14 @@ class MyScopeMetadataResolver extends AnnotationScopeMetadataResolver { |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan( |
|
|
|
@ComponentScan( |
|
|
|
basePackages="org.springframework.context.annotation", |
|
|
|
basePackages = "org.springframework.context.annotation", |
|
|
|
useDefaultFilters=false, |
|
|
|
useDefaultFilters = false, |
|
|
|
includeFilters = @Filter(type = FilterType.CUSTOM, classes = ComponentScanParserTests.CustomTypeFilter.class), |
|
|
|
includeFilters = @Filter(type = FilterType.CUSTOM, classes = ComponentScanParserTests.CustomTypeFilter.class), |
|
|
|
// exclude this class from scanning since it's in the scanned package
|
|
|
|
// exclude this class from scanning since it's in the scanned package
|
|
|
|
excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ComponentScanWithCustomTypeFilter.class), |
|
|
|
excludeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ComponentScanWithCustomTypeFilter.class), |
|
|
|
lazyInit = true) |
|
|
|
lazyInit = true) |
|
|
|
class ComponentScanWithCustomTypeFilter { |
|
|
|
class ComponentScanWithCustomTypeFilter { |
|
|
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
@Bean |
|
|
|
@SuppressWarnings({ "rawtypes", "serial", "unchecked" }) |
|
|
|
@SuppressWarnings({ "rawtypes", "serial", "unchecked" }) |
|
|
|
public static CustomAutowireConfigurer customAutowireConfigurer() { |
|
|
|
public static CustomAutowireConfigurer customAutowireConfigurer() { |
|
|
|
@ -318,30 +327,30 @@ class ComponentScanWithCustomTypeFilter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan(basePackages="example.scannable", |
|
|
|
@ComponentScan(basePackages = "example.scannable", |
|
|
|
scopedProxy=ScopedProxyMode.INTERFACES, |
|
|
|
scopedProxy = ScopedProxyMode.INTERFACES, |
|
|
|
useDefaultFilters=false, |
|
|
|
useDefaultFilters = false, |
|
|
|
includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ScopedProxyTestBean.class)) |
|
|
|
includeFilters = @Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ScopedProxyTestBean.class)) |
|
|
|
class ComponentScanWithScopedProxy {} |
|
|
|
class ComponentScanWithScopedProxy {} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan(basePackages="example.scannable", |
|
|
|
@ComponentScan(basePackages = "example.scannable", |
|
|
|
scopedProxy=ScopedProxyMode.INTERFACES, |
|
|
|
scopedProxy = ScopedProxyMode.INTERFACES, |
|
|
|
useDefaultFilters=false, |
|
|
|
useDefaultFilters = false, |
|
|
|
includeFilters=@Filter(type=FilterType.REGEX, pattern ="((?:[a-z.]+))ScopedProxyTestBean")) |
|
|
|
includeFilters = @Filter(type=FilterType.REGEX, pattern = "((?:[a-z.]+))ScopedProxyTestBean")) |
|
|
|
class ComponentScanWithScopedProxyThroughRegex {} |
|
|
|
class ComponentScanWithScopedProxyThroughRegex {} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan(basePackages="example.scannable", |
|
|
|
@ComponentScan(basePackages = "example.scannable", |
|
|
|
scopedProxy=ScopedProxyMode.INTERFACES, |
|
|
|
scopedProxy = ScopedProxyMode.INTERFACES, |
|
|
|
useDefaultFilters=false, |
|
|
|
useDefaultFilters = false, |
|
|
|
includeFilters=@Filter(type=FilterType.ASPECTJ, pattern ="*..ScopedProxyTestBean")) |
|
|
|
includeFilters = @Filter(type=FilterType.ASPECTJ, pattern = "*..ScopedProxyTestBean")) |
|
|
|
class ComponentScanWithScopedProxyThroughAspectJPattern {} |
|
|
|
class ComponentScanWithScopedProxyThroughAspectJPattern {} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan(basePackages="example.scannable", |
|
|
|
@ComponentScan(basePackages = "example.scannable", |
|
|
|
useDefaultFilters=false, |
|
|
|
useDefaultFilters = false, |
|
|
|
includeFilters={ |
|
|
|
includeFilters = { |
|
|
|
@Filter(CustomStereotype.class), |
|
|
|
@Filter(CustomStereotype.class), |
|
|
|
@Filter(CustomComponent.class) |
|
|
|
@Filter(CustomComponent.class) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -349,15 +358,15 @@ class ComponentScanWithScopedProxyThroughAspectJPattern {} |
|
|
|
class ComponentScanWithMultipleAnnotationIncludeFilters1 {} |
|
|
|
class ComponentScanWithMultipleAnnotationIncludeFilters1 {} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan(basePackages="example.scannable", |
|
|
|
@ComponentScan(basePackages = "example.scannable", |
|
|
|
useDefaultFilters=false, |
|
|
|
useDefaultFilters = false, |
|
|
|
includeFilters=@Filter({CustomStereotype.class, CustomComponent.class}) |
|
|
|
includeFilters = @Filter({CustomStereotype.class, CustomComponent.class}) |
|
|
|
) |
|
|
|
) |
|
|
|
class ComponentScanWithMultipleAnnotationIncludeFilters2 {} |
|
|
|
class ComponentScanWithMultipleAnnotationIncludeFilters2 {} |
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
@Configuration |
|
|
|
@ComponentScan( |
|
|
|
@ComponentScan( |
|
|
|
value="example.scannable", |
|
|
|
value = "example.scannable", |
|
|
|
basePackages="example.scannable", |
|
|
|
basePackages = "example.scannable", |
|
|
|
basePackageClasses=example.scannable._package.class) |
|
|
|
basePackageClasses = example.scannable._package.class) |
|
|
|
class ComponentScanWithBasePackagesAndValueAlias {} |
|
|
|
class ComponentScanWithBasePackagesAndValueAlias {} |
|
|
|
|