Refined tests for FactoryBean return type resolution on @Bean methods
Issue: SPR-11842
This commit is contained in:
parent
85b2c7d116
commit
ae66e45887
|
|
@ -18,12 +18,15 @@ package org.springframework.remoting.httpinvoker;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
@ -35,9 +38,18 @@ import static org.junit.Assert.*;
|
||||||
public class HttpInvokerFactoryBeanIntegrationTests {
|
public class HttpInvokerFactoryBeanIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void foo() {
|
public void testLoadedConfigClass() {
|
||||||
ApplicationContext context = new AnnotationConfigApplicationContext(InvokerAutowiringConfig.class);
|
ApplicationContext context = new AnnotationConfigApplicationContext(InvokerAutowiringConfig.class);
|
||||||
MyBean myBean = context.getBean(MyBean.class);
|
MyBean myBean = context.getBean("myBean", MyBean.class);
|
||||||
|
assertSame(context.getBean("myService"), myBean.myService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonLoadedConfigClass() {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
context.registerBeanDefinition("config", new RootBeanDefinition(InvokerAutowiringConfig.class.getName()));
|
||||||
|
context.refresh();
|
||||||
|
MyBean myBean = context.getBean("myBean", MyBean.class);
|
||||||
assertSame(context.getBean("myService"), myBean.myService);
|
assertSame(context.getBean("myService"), myBean.myService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -46,7 +58,7 @@ public class HttpInvokerFactoryBeanIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component("myBean")
|
||||||
public static class MyBean {
|
public static class MyBean {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -56,6 +68,7 @@ public class HttpInvokerFactoryBeanIntegrationTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan
|
@ComponentScan
|
||||||
|
@Lazy
|
||||||
public static class InvokerAutowiringConfig {
|
public static class InvokerAutowiringConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -65,6 +78,11 @@ public class HttpInvokerFactoryBeanIntegrationTests {
|
||||||
factory.setServiceInterface(MyService.class);
|
factory.setServiceInterface(MyService.class);
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public FactoryBean<String> myOtherService() {
|
||||||
|
throw new IllegalStateException("Don't ever call me");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue