Skip to content

Commit ae66e45

Browse files
committed
Refined tests for FactoryBean return type resolution on @bean methods
Issue: SPR-11842
1 parent 85b2c7d commit ae66e45

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpInvokerFactoryBeanIntegrationTests.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818

1919
import org.junit.Test;
2020

21+
import org.springframework.beans.factory.FactoryBean;
2122
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.beans.factory.support.RootBeanDefinition;
2224
import org.springframework.context.ApplicationContext;
2325
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2426
import org.springframework.context.annotation.Bean;
2527
import org.springframework.context.annotation.ComponentScan;
2628
import org.springframework.context.annotation.Configuration;
29+
import org.springframework.context.annotation.Lazy;
2730
import org.springframework.stereotype.Component;
2831

2932
import static org.junit.Assert.*;
@@ -35,9 +38,18 @@
3538
public 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

Comments
 (0)