18
18
19
19
import org .junit .Test ;
20
20
21
+ import org .springframework .beans .factory .FactoryBean ;
21
22
import org .springframework .beans .factory .annotation .Autowired ;
23
+ import org .springframework .beans .factory .support .RootBeanDefinition ;
22
24
import org .springframework .context .ApplicationContext ;
23
25
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
24
26
import org .springframework .context .annotation .Bean ;
25
27
import org .springframework .context .annotation .ComponentScan ;
26
28
import org .springframework .context .annotation .Configuration ;
29
+ import org .springframework .context .annotation .Lazy ;
27
30
import org .springframework .stereotype .Component ;
28
31
29
32
import static org .junit .Assert .*;
35
38
public class HttpInvokerFactoryBeanIntegrationTests {
36
39
37
40
@ Test
38
- public void foo () {
41
+ public void testLoadedConfigClass () {
39
42
ApplicationContext context = new AnnotationConfigApplicationContext (InvokerAutowiringConfig .class );
40
- MyBean myBean = context .getBean (MyBean .class );
43
+ MyBean myBean = context .getBean ("myBean" , MyBean .class );
44
+ assertSame (context .getBean ("myService" ), myBean .myService );
45
+ }
46
+
47
+ @ Test
48
+ public void testNonLoadedConfigClass () {
49
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
50
+ context .registerBeanDefinition ("config" , new RootBeanDefinition (InvokerAutowiringConfig .class .getName ()));
51
+ context .refresh ();
52
+ MyBean myBean = context .getBean ("myBean" , MyBean .class );
41
53
assertSame (context .getBean ("myService" ), myBean .myService );
42
54
}
43
55
@@ -46,7 +58,7 @@ public interface MyService {
46
58
}
47
59
48
60
49
- @ Component
61
+ @ Component ( "myBean" )
50
62
public static class MyBean {
51
63
52
64
@ Autowired
@@ -56,6 +68,7 @@ public static class MyBean {
56
68
57
69
@ Configuration
58
70
@ ComponentScan
71
+ @ Lazy
59
72
public static class InvokerAutowiringConfig {
60
73
61
74
@ Bean
@@ -65,6 +78,11 @@ public HttpInvokerProxyFactoryBean myService() {
65
78
factory .setServiceInterface (MyService .class );
66
79
return factory ;
67
80
}
81
+
82
+ @ Bean
83
+ public FactoryBean <String > myOtherService () {
84
+ throw new IllegalStateException ("Don't ever call me" );
85
+ }
68
86
}
69
87
70
88
}
0 commit comments