Spring 从父应用运行并关闭子上下文

Spring 从父应用运行并关闭子上下文,spring,spring-cloud-task,Spring,Spring Cloud Task,我正在使用SpringApplicationBuilder从父级运行子上下文应用程序(SpringCloud任务)。我还将运行的父上下文传递给子应用程序的构建器——它定义了数据源bean,我希望任务也使用它 我的问题是,当关闭子上下文时,所有父bean也会被销毁。 我做错什么了吗 如何从父上下文与子上下文共享bean,并在子上下文退出时使它们保持活动状态 @Component public class ClassInParentContext{ @Autowired private Con

我正在使用SpringApplicationBuilder从父级运行子上下文应用程序(SpringCloud任务)。我还将运行的父上下文传递给子应用程序的构建器——它定义了数据源bean,我希望任务也使用它

我的问题是,当关闭子上下文时,所有父bean也会被销毁。 我做错什么了吗

如何从父上下文与子上下文共享bean,并在子上下文退出时使它们保持活动状态

@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{
}

感谢在与
spring cloud task
团队交谈后发现,当任务结束时,父上下文隐式、强制和故意关闭。

不要描述您的代码。发布。@JBNizet,我已经添加了代码示例