Created
October 15, 2013 17:53
-
-
Save rwinch/6995720 to your computer and use it in GitHub Desktop.
Imported Configuration can reference beans from Configuration that imported it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.Import; | |
public class Test { | |
public static void main(String[] args) { | |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(A.class); | |
try { | |
B bean = context.getBean(B.class); | |
if(bean.c == null) { | |
throw new IllegalStateException("Failed!"); | |
} | |
else { | |
System.out.println("SUCESS!!!!!!!!!!!!!!!!!!!"); | |
} | |
} finally { | |
context.close(); | |
} | |
} | |
@Import(B.class) | |
@Configuration | |
static class A { | |
@Bean | |
public C c() { return new C(); } | |
} | |
@Configuration | |
static class B { | |
@Autowired | |
private C c; | |
} | |
static class C {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment