1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.context.annotation;
18
19 import org.junit.Test;
20
21 import org.springframework.context.annotation.componentscan.cycle.left.LeftConfig;
22 import org.springframework.context.annotation.componentscan.level1.Level1Config;
23 import org.springframework.context.annotation.componentscan.level2.Level2Config;
24 import org.springframework.context.annotation.componentscan.level3.Level3Component;
25
26 import static org.hamcrest.CoreMatchers.*;
27 import static org.junit.Assert.*;
28
29
30
31
32
33
34
35
36 public class ComponentScanAnnotationRecursionTests {
37
38 @Test
39 public void recursion() {
40 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
41 ctx.register(Level1Config.class);
42 ctx.refresh();
43
44
45 ctx.getBean(Level1Config.class);
46 ctx.getBean(Level2Config.class);
47 ctx.getBean(Level3Component.class);
48
49
50 assertThat(ctx.getBean("level1Bean"), sameInstance(ctx.getBean("level1Bean")));
51 assertThat(ctx.getBean("level2Bean"), sameInstance(ctx.getBean("level2Bean")));
52 }
53
54 public void evenCircularScansAreSupported() {
55 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
56 ctx.register(LeftConfig.class);
57 ctx.refresh();
58 ctx.getBean("leftConfig");
59 ctx.getBean("rightConfig");
60 }
61
62 }