44
44
import org .springframework .beans .factory .config .BeanDefinition ;
45
45
import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
46
46
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
47
+ import org .springframework .context .ApplicationContext ;
47
48
import org .springframework .context .EnvironmentAware ;
48
49
import org .springframework .context .ResourceLoaderAware ;
49
50
import org .springframework .context .annotation .ComponentScan .Filter ;
@@ -143,6 +144,15 @@ public void viaContextRegistration_WithComposedAnnotation() {
143
144
.isTrue ();
144
145
}
145
146
147
+ @ Test
148
+ void multipleComposedComponentScanAnnotations () { // gh-30941
149
+ ApplicationContext ctx = new AnnotationConfigApplicationContext (MultipleComposedAnnotationsConfig .class );
150
+ ctx .getBean (MultipleComposedAnnotationsConfig .class );
151
+ assertContextContainsBean (ctx , "componentScanAnnotationIntegrationTests.MultipleComposedAnnotationsConfig" );
152
+ assertContextContainsBean (ctx , "simpleComponent" );
153
+ assertContextContainsBean (ctx , "barComponent" );
154
+ }
155
+
146
156
@ Test
147
157
public void viaBeanRegistration () {
148
158
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
@@ -267,6 +277,10 @@ public void withBasePackagesAndValueAlias() {
267
277
assertThat (ctx .containsBean ("fooServiceImpl" )).isTrue ();
268
278
}
269
279
280
+ private static void assertContextContainsBean (ApplicationContext ctx , String beanName ) {
281
+ assertThat (ctx .containsBean (beanName )).as ("context contains bean " + beanName ).isTrue ();
282
+ }
283
+
270
284
271
285
@ Configuration
272
286
@ ComponentScan
@@ -278,10 +292,25 @@ public void withBasePackagesAndValueAlias() {
278
292
String [] basePackages () default {};
279
293
}
280
294
295
+ @ Configuration
296
+ @ ComponentScan
297
+ @ Retention (RetentionPolicy .RUNTIME )
298
+ @ Target (ElementType .TYPE )
299
+ public @interface ComposedConfiguration2 {
300
+
301
+ @ AliasFor (annotation = ComponentScan .class )
302
+ String [] basePackages () default {};
303
+ }
304
+
281
305
@ ComposedConfiguration (basePackages = "org.springframework.context.annotation.componentscan.simple" )
282
306
public static class ComposedAnnotationConfig {
283
307
}
284
308
309
+ @ ComposedConfiguration (basePackages = "org.springframework.context.annotation.componentscan.simple" )
310
+ @ ComposedConfiguration2 (basePackages = "example.scannable.sub" )
311
+ static class MultipleComposedAnnotationsConfig {
312
+ }
313
+
285
314
public static class AwareTypeFilter implements TypeFilter , EnvironmentAware ,
286
315
ResourceLoaderAware , BeanClassLoaderAware , BeanFactoryAware {
287
316
0 commit comments