1818
1919import org .junit .Test ;
2020
21+ import org .springframework .beans .factory .FactoryBean ;
2122import org .springframework .beans .factory .annotation .Autowired ;
23+ import org .springframework .beans .factory .support .RootBeanDefinition ;
2224import org .springframework .context .ApplicationContext ;
2325import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
2426import org .springframework .context .annotation .Bean ;
2527import org .springframework .context .annotation .ComponentScan ;
2628import org .springframework .context .annotation .Configuration ;
29+ import org .springframework .context .annotation .Lazy ;
2730import org .springframework .stereotype .Component ;
2831
2932import static org .junit .Assert .*;
3538public class HttpInvokerFactoryBeanIntegrationTests {
3639
3740 @ Test
38- public void foo () {
41+ public void testLoadedConfigClass () {
3942 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 );
4153 assertSame (context .getBean ("myService" ), myBean .myService );
4254 }
4355
@@ -46,7 +58,7 @@ public interface MyService {
4658 }
4759
4860
49- @ Component
61+ @ Component ( "myBean" )
5062 public static class MyBean {
5163
5264 @ Autowired
@@ -56,6 +68,7 @@ public static class MyBean {
5668
5769 @ Configuration
5870 @ ComponentScan
71+ @ Lazy
5972 public static class InvokerAutowiringConfig {
6073
6174 @ Bean
@@ -65,6 +78,11 @@ public HttpInvokerProxyFactoryBean myService() {
6578 factory .setServiceInterface (MyService .class );
6679 return factory ;
6780 }
81+
82+ @ Bean
83+ public FactoryBean <String > myOtherService () {
84+ throw new IllegalStateException ("Don't ever call me" );
85+ }
6886 }
6987
7088}
0 commit comments