16
16
17
17
package org .springframework .context .annotation ;
18
18
19
- import java .io .IOException ;
20
19
import java .lang .annotation .ElementType ;
21
20
import java .lang .annotation .Retention ;
22
21
import java .lang .annotation .RetentionPolicy ;
@@ -209,7 +208,7 @@ void withScopedProxy() throws Exception {
209
208
}
210
209
211
210
@ Test
212
- void withScopedProxyThroughRegex () throws IOException , ClassNotFoundException {
211
+ void withScopedProxyThroughRegex () {
213
212
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ();
214
213
ctx .register (ComponentScanWithScopedProxyThroughRegex .class );
215
214
ctx .getBeanFactory ().registerScope ("myScope" , new SimpleMapScope ());
@@ -221,7 +220,7 @@ void withScopedProxyThroughRegex() throws IOException, ClassNotFoundException {
221
220
}
222
221
223
222
@ Test
224
- void withScopedProxyThroughAspectJPattern () throws IOException , ClassNotFoundException {
223
+ void withScopedProxyThroughAspectJPattern () {
225
224
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ();
226
225
ctx .register (ComponentScanWithScopedProxyThroughAspectJPattern .class );
227
226
ctx .getBeanFactory ().registerScope ("myScope" , new SimpleMapScope ());
@@ -233,21 +232,38 @@ void withScopedProxyThroughAspectJPattern() throws IOException, ClassNotFoundExc
233
232
}
234
233
235
234
@ Test
236
- void withMultipleAnnotationIncludeFilters1 () throws IOException , ClassNotFoundException {
235
+ void withMultipleAnnotationIncludeFilters1 () {
237
236
AnnotationConfigApplicationContext ctx =
238
237
new AnnotationConfigApplicationContext (ComponentScanWithMultipleAnnotationIncludeFilters1 .class );
239
238
ctx .getBean (DefaultNamedComponent .class ); // @CustomStereotype-annotated
240
239
ctx .getBean (MessageBean .class ); // @CustomComponent-annotated
241
240
}
242
241
243
242
@ Test
244
- void withMultipleAnnotationIncludeFilters2 () throws IOException , ClassNotFoundException {
243
+ void withMultipleAnnotationIncludeFilters2 () {
245
244
AnnotationConfigApplicationContext ctx =
246
245
new AnnotationConfigApplicationContext (ComponentScanWithMultipleAnnotationIncludeFilters2 .class );
247
246
ctx .getBean (DefaultNamedComponent .class ); // @CustomStereotype-annotated
248
247
ctx .getBean (MessageBean .class ); // @CustomComponent-annotated
249
248
}
250
249
250
+ @ Test
251
+ void withBeanMethodOverride () {
252
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ();
253
+ ctx .register (ComponentScanWithMultipleAnnotationIncludeFilters3 .class );
254
+ ctx .refresh ();
255
+ assertThat (ctx .getBean (DefaultNamedComponent .class ).toString ()).isEqualTo ("overridden" );
256
+ }
257
+
258
+ @ Test
259
+ void withBeanMethodOverrideAndGeneralOverridingDisabled () {
260
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ();
261
+ ctx .getDefaultListableBeanFactory ().setAllowBeanDefinitionOverriding (false );
262
+ ctx .register (ComponentScanWithMultipleAnnotationIncludeFilters3 .class );
263
+ ctx .refresh ();
264
+ assertThat (ctx .getBean (DefaultNamedComponent .class ).toString ()).isEqualTo ("overridden" );
265
+ }
266
+
251
267
@ Test
252
268
void withBasePackagesAndValueAlias () {
253
269
AnnotationConfigApplicationContext ctx =
@@ -292,6 +308,7 @@ static class ComposedAnnotationConfig {
292
308
static class MultipleComposedAnnotationsConfig {
293
309
}
294
310
311
+
295
312
static class AwareTypeFilter implements TypeFilter , EnvironmentAware ,
296
313
ResourceLoaderAware , BeanClassLoaderAware , BeanFactoryAware {
297
314
@@ -329,10 +346,8 @@ public boolean match(MetadataReader metadataReader, MetadataReaderFactory metada
329
346
assertThat (this .environment ).isNotNull ();
330
347
return false ;
331
348
}
332
-
333
349
}
334
350
335
-
336
351
}
337
352
338
353
@@ -461,11 +476,27 @@ class ComponentScanWithMultipleAnnotationIncludeFilters1 {}
461
476
)
462
477
class ComponentScanWithMultipleAnnotationIncludeFilters2 {}
463
478
479
+ @ Configuration
480
+ @ ComponentScan (basePackages = "example.scannable" ,
481
+ useDefaultFilters = false ,
482
+ includeFilters = @ Filter ({CustomStereotype .class , CustomComponent .class })
483
+ )
484
+ class ComponentScanWithMultipleAnnotationIncludeFilters3 {
485
+
486
+ @ Bean
487
+ public DefaultNamedComponent thoreau () {
488
+ return new DefaultNamedComponent () {
489
+ @ Override
490
+ public String toString () {
491
+ return "overridden" ;
492
+ }
493
+ };
494
+ }
495
+ }
496
+
464
497
@ Configuration
465
498
@ ComponentScan (
466
499
value = "example.scannable" ,
467
500
basePackages = "example.scannable" ,
468
501
basePackageClasses = example .scannable .PackageMarker .class )
469
502
class ComponentScanWithBasePackagesAndValueAlias {}
470
-
471
-
0 commit comments