Hi,
can we dynamically add one existing bean into spring AnnotationConfigApplicationContext when we initialize the context?
e.g. I have this spring java config:
Then, when I initialize AnnotationConfigApplicationContext, I want to dynamically add MyBean instance into context, e.g.Code:@Configuration public class MyConfig { @Autowire public MyBean mybean; @Bean public AnotherBean another() { return new AnotherBean( mybean ); } }
Could you please let me know how I can add mybean instance to AnnotationConfigApplicationContext?Code:MyBean mybean = createMyBean.... AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext() //context.add(mybean ) // so MyConfig below can autowire mybean instance context.register(classOf[MyConfig ])
David


Reply With Quote