@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2014 the original author or authors .
* Copyright 2002 - 2015 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -19,13 +19,17 @@ package org.springframework.context.annotation;
@@ -19,13 +19,17 @@ package org.springframework.context.annotation;
import org.junit.Test ;
import org.springframework.beans.factory.FactoryBean ;
import org.springframework.beans.factory.InitializingBean ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.util.Assert ;
import static org.junit.Assert.* ;
/ * *
* Tests cornering bug SPR - 8514 .
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3 . 1
* /
public class ConfigurationWithFactoryBeanAndAutowiringTests {
@ -77,30 +81,52 @@ public class ConfigurationWithFactoryBeanAndAutowiringTests {
@@ -77,30 +81,52 @@ public class ConfigurationWithFactoryBeanAndAutowiringTests {
ctx . register ( WildcardParameterizedFactoryBeanInterfaceConfig . class ) ;
ctx . refresh ( ) ;
}
@Test
public void withFactoryBeanCallingBean ( ) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ( ) ;
ctx . register ( AppConfig . class ) ;
ctx . register ( FactoryBeanCallingConfig . class ) ;
ctx . refresh ( ) ;
assertEquals ( "true" , ctx . getBean ( "myString" ) ) ;
}
class DummyBean {
static class DummyBean {
}
class MyFactoryBean implements FactoryBean < String > {
static class MyFactoryBean implements FactoryBean < String > , InitializingBean {
private boolean initialized = false ;
@Override
public void afterPropertiesSet ( ) throws Exception {
this . initialized = true ;
}
@Override
public String getObject ( ) throws Exception {
return "foo" ;
}
@Override
public Class < String > getObjectType ( ) {
return String . class ;
}
@Override
public boolean isSingleton ( ) {
return true ;
}
public String getString ( ) {
return Boolean . toString ( this . initialized ) ;
}
}
class MyParameterizedFactoryBean < T > implements FactoryBean < T > {
static class MyParameterizedFactoryBean < T > implements FactoryBean < T > {
private final T obj ;
@ -127,7 +153,8 @@ class MyParameterizedFactoryBean<T> implements FactoryBean<T> {
@@ -127,7 +153,8 @@ class MyParameterizedFactoryBean<T> implements FactoryBean<T> {
@Configuration
class AppConfig {
static class AppConfig {
@Bean
public DummyBean dummyBean ( ) {
return new DummyBean ( ) ;
@ -136,7 +163,8 @@ class AppConfig {
@@ -136,7 +163,8 @@ class AppConfig {
@Configuration
class ConcreteFactoryBeanImplementationConfig {
static class ConcreteFactoryBeanImplementationConfig {
@Autowired
private DummyBean dummyBean ;
@ -149,7 +177,8 @@ class ConcreteFactoryBeanImplementationConfig {
@@ -149,7 +177,8 @@ class ConcreteFactoryBeanImplementationConfig {
@Configuration
class ParameterizedFactoryBeanImplementationConfig {
static class ParameterizedFactoryBeanImplementationConfig {
@Autowired
private DummyBean dummyBean ;
@ -162,7 +191,8 @@ class ParameterizedFactoryBeanImplementationConfig {
@@ -162,7 +191,8 @@ class ParameterizedFactoryBeanImplementationConfig {
@Configuration
class ParameterizedFactoryBeanInterfaceConfig {
static class ParameterizedFactoryBeanInterfaceConfig {
@Autowired
private DummyBean dummyBean ;
@ -175,7 +205,8 @@ class ParameterizedFactoryBeanInterfaceConfig {
@@ -175,7 +205,8 @@ class ParameterizedFactoryBeanInterfaceConfig {
@Configuration
class NonPublicParameterizedFactoryBeanInterfaceConfig {
static class NonPublicParameterizedFactoryBeanInterfaceConfig {
@Autowired
private DummyBean dummyBean ;
@ -188,7 +219,8 @@ class NonPublicParameterizedFactoryBeanInterfaceConfig {
@@ -188,7 +219,8 @@ class NonPublicParameterizedFactoryBeanInterfaceConfig {
@Configuration
class RawFactoryBeanInterfaceConfig {
static class RawFactoryBeanInterfaceConfig {
@Autowired
private DummyBean dummyBean ;
@ -202,7 +234,8 @@ class RawFactoryBeanInterfaceConfig {
@@ -202,7 +234,8 @@ class RawFactoryBeanInterfaceConfig {
@Configuration
class WildcardParameterizedFactoryBeanInterfaceConfig {
static class WildcardParameterizedFactoryBeanInterfaceConfig {
@Autowired
private DummyBean dummyBean ;
@ -212,3 +245,24 @@ class WildcardParameterizedFactoryBeanInterfaceConfig {
@@ -212,3 +245,24 @@ class WildcardParameterizedFactoryBeanInterfaceConfig {
return new MyFactoryBean ( ) ;
}
}
@Configuration
static class FactoryBeanCallingConfig {
@Autowired
private DummyBean dummyBean ;
@Bean
public MyFactoryBean factoryBean ( ) {
Assert . notNull ( dummyBean , "DummyBean was not injected." ) ;
return new MyFactoryBean ( ) ;
}
@Bean
public String myString ( ) {
return factoryBean ( ) . getString ( ) ;
}
}
}