|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2014 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.context.annotation;
|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
| 20 | +import java.lang.annotation.ElementType; |
| 21 | +import java.lang.annotation.Retention; |
| 22 | +import java.lang.annotation.RetentionPolicy; |
| 23 | +import java.lang.annotation.Target; |
20 | 24 | import java.util.HashSet;
|
21 | 25 |
|
22 | 26 | import example.scannable.CustomComponent;
|
|
28 | 32 | import example.scannable_implicitbasepackage.ComponentScanAnnotatedConfigWithImplicitBasePackage;
|
29 | 33 | import example.scannable_scoped.CustomScopeAnnotationBean;
|
30 | 34 | import example.scannable_scoped.MyScope;
|
31 |
| -import org.junit.Test; |
32 | 35 |
|
| 36 | +import org.junit.Test; |
33 | 37 | import org.springframework.aop.support.AopUtils;
|
34 | 38 | import org.springframework.beans.factory.annotation.CustomAutowireConfigurer;
|
35 | 39 | import org.springframework.beans.factory.config.BeanDefinition;
|
36 | 40 | import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
37 | 41 | import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
38 | 42 | import org.springframework.context.annotation.ComponentScan.Filter;
|
39 | 43 | import org.springframework.context.annotation.ComponentScanParserTests.CustomAnnotationAutowiredBean;
|
| 44 | +import org.springframework.context.annotation.componentscan.simple.SimpleComponent; |
40 | 45 | import org.springframework.context.support.GenericApplicationContext;
|
41 | 46 | import org.springframework.tests.context.SimpleMapScope;
|
42 | 47 | import org.springframework.util.SerializationTestUtils;
|
|
50 | 55 | *
|
51 | 56 | * @author Chris Beams
|
52 | 57 | * @author Juergen Hoeller
|
| 58 | + * @author Sam Brannen |
53 | 59 | * @since 3.1
|
54 | 60 | */
|
| 61 | +@SuppressWarnings("resource") |
55 | 62 | public class ComponentScanAnnotationIntegrationTests {
|
56 | 63 |
|
57 | 64 | @Test
|
@@ -101,6 +108,20 @@ public void viaContextRegistration_FromPackageOfConfigClass() {
|
101 | 108 | ctx.containsBean("scannedComponent"), is(true));
|
102 | 109 | }
|
103 | 110 |
|
| 111 | + @Test |
| 112 | + public void viaContextRegistration_WithComposedAnnotation() { |
| 113 | + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
| 114 | + ctx.register(ComposedAnnotationConfig.class); |
| 115 | + ctx.refresh(); |
| 116 | + ctx.getBean(ComposedAnnotationConfig.class); |
| 117 | + ctx.getBean(SimpleComponent.class); |
| 118 | + assertThat("config class bean not found", |
| 119 | + ctx.containsBeanDefinition("componentScanAnnotationIntegrationTests.ComposedAnnotationConfig"), is(true)); |
| 120 | + assertThat("@ComponentScan annotated @Configuration class registered directly against " |
| 121 | + + "AnnotationConfigApplicationContext did not trigger component scanning as expected", |
| 122 | + ctx.containsBean("simpleComponent"), is(true)); |
| 123 | + } |
| 124 | + |
104 | 125 | @Test
|
105 | 126 | public void viaBeanRegistration() {
|
106 | 127 | DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
@@ -209,6 +230,22 @@ public void withBasePackagesAndValueAlias() {
|
209 | 230 | assertThat(ctx.containsBean("fooServiceImpl"), is(true));
|
210 | 231 | }
|
211 | 232 |
|
| 233 | + |
| 234 | + @Configuration |
| 235 | + @ComponentScan |
| 236 | + @Retention(RetentionPolicy.RUNTIME) |
| 237 | + @Target(ElementType.TYPE) |
| 238 | + public static @interface ComposedConfiguration { |
| 239 | + |
| 240 | + String[] basePackages() default {}; |
| 241 | + |
| 242 | + String[] bundles() default {}; |
| 243 | + } |
| 244 | + |
| 245 | + @ComposedConfiguration(basePackages = "org.springframework.context.annotation.componentscan.simple") |
| 246 | + public static class ComposedAnnotationConfig { |
| 247 | + } |
| 248 | + |
212 | 249 | }
|
213 | 250 |
|
214 | 251 |
|
|
0 commit comments