@ -16,9 +16,14 @@
@@ -16,9 +16,14 @@
package org.springframework.context.annotation ;
import static org.hamcrest.CoreMatchers.instanceOf ;
import static org.hamcrest.CoreMatchers.is ;
import static org.junit.Assert.assertThat ;
import org.junit.Test ;
import org.springframework.context.annotation.configuration.StubSpecification ;
import org.springframework.context.config.FeatureSpecification ;
import org.springframework.core.io.ResourceLoader ;
public class FeatureConfigurationClassTests {
@ -29,6 +34,14 @@ public class FeatureConfigurationClassTests {
@@ -29,6 +34,14 @@ public class FeatureConfigurationClassTests {
ctx . refresh ( ) ;
}
@Test
public void featureMethodsMayAcceptResourceLoaderParameter ( ) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ( ) ;
ctx . setDisplayName ( "enclosing app ctx" ) ;
ctx . register ( FeatureMethodWithResourceLoaderParameter . class ) ;
ctx . refresh ( ) ;
}
}
@ -50,3 +63,15 @@ class FeatureConfigWithBeanAnnotatedMethod {
@@ -50,3 +63,15 @@ class FeatureConfigWithBeanAnnotatedMethod {
return new StubSpecification ( ) ;
}
}
@FeatureConfiguration
class FeatureMethodWithResourceLoaderParameter {
@Feature
public FeatureSpecification feature ( ResourceLoader rl ) {
// prove that the injected ResourceLoader is actually the enclosing application context
Object target = ( ( EarlyBeanReferenceProxy ) rl ) . dereferenceTargetBean ( ) ;
assertThat ( target , instanceOf ( AnnotationConfigApplicationContext . class ) ) ;
assertThat ( ( ( AnnotationConfigApplicationContext ) target ) . getDisplayName ( ) , is ( "enclosing app ctx" ) ) ;
return new StubSpecification ( ) ;
}
}