I'm using spring application builder to run child context application (spring Cloud task) from parent. I'm also passing running parent context to the builder of child application - it has DataSource bean defined and I want it to be used by task as well.
My problem is that when the child context is closed, all parent bean are also destroyed. Am I doing something wrong?
How can I share beans from parent context with child and still keep them alive when the child context exits.
@Component
public class ClassInParentContext{
@Autowired
private ConfigurableApplicationContext parentAppCtx;
@Autowired
private DataSource ds; //this bean is defined in parent context and I want it to be passed to child but not to be disposed when the child context closes.
public void onSomeEventInParentContext(){
new SpringApplicationBuilder(com.app.child.Child.class)
.parent(parentAppCtx)
.run(args); //this context is autoclosed by spring cloud task
}
}
@EnableTask
public class Child{
}
Thanks