Skip to content

Commit ef290ff

Browse files
committed
Additional tests for configuration class importing via ASM
Issue: SPR-11647 (cherry picked from commit 8c9116f)
1 parent ae45794 commit ef290ff

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

spring-context/src/test/java/org/springframework/context/annotation/ComponentScanAndImportAnnotationInteractionTests.java

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@
1717
package org.springframework.context.annotation;
1818

1919
import org.junit.Test;
20+
21+
import org.springframework.beans.factory.support.RootBeanDefinition;
2022
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
2123

2224
/**
@@ -36,17 +38,61 @@ public void componentScanOverlapsWithImport() {
3638
ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
3739
}
3840

41+
@Test
42+
public void componentScanOverlapsWithImportUsingAsm() {
43+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
44+
ctx.registerBeanDefinition("config1", new RootBeanDefinition(Config1.class.getName()));
45+
ctx.registerBeanDefinition("config2", new RootBeanDefinition(Config2.class.getName()));
46+
ctx.refresh(); // no conflicts found trying to register SimpleComponent
47+
ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent
48+
}
49+
50+
@Test
51+
public void componentScanViaImport() {
52+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
53+
ctx.register(Config3.class);
54+
ctx.refresh();
55+
ctx.getBean(SimpleComponent.class);
56+
}
57+
58+
@Test
59+
public void componentScanViaImportUsingAsm() {
60+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
61+
ctx.registerBeanDefinition("config4", new RootBeanDefinition(Config3.class.getName()));
62+
ctx.refresh();
63+
ctx.getBean(SimpleComponent.class);
64+
}
65+
66+
@Test
67+
public void componentScanViaImportUsingScan() {
68+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
69+
ctx.scan("org.springframework.context.annotation.componentscan.importing");
70+
ctx.refresh();
71+
ctx.getBean(SimpleComponent.class);
72+
}
73+
3974

4075
@Configuration
4176
@ComponentScan("org.springframework.context.annotation.componentscan.simple")
4277
static class Config1 {
43-
4478
}
4579

4680

4781
@Configuration
4882
@Import(org.springframework.context.annotation.componentscan.simple.SimpleComponent.class)
4983
static class Config2 {
84+
}
85+
5086

87+
@Configuration
88+
@Import(ImportedConfig.class)
89+
static class Config3 {
5190
}
91+
92+
93+
@Configuration
94+
@ComponentScan("org.springframework.context.annotation.componentscan.simple")
95+
public static class ImportedConfig {
96+
}
97+
5298
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2002-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.context.annotation.componentscan.importing;
18+
19+
import org.springframework.context.annotation.ComponentScanAndImportAnnotationInteractionTests;
20+
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.context.annotation.Import;
22+
23+
@Configuration
24+
@Import(ComponentScanAndImportAnnotationInteractionTests.ImportedConfig.class)
25+
public class ImportingConfig {
26+
}

0 commit comments

Comments
 (0)