AnnotationConfigApplicationContext and parent context

后端 未结 5 682
暖寄归人
暖寄归人 2021-01-03 05:29

I\'m facing an issue trying to define a context hierarchy using AnnotationConfigApplicationContext.

The problem is when defining a module context insid

5条回答
  •  独厮守ぢ
    2021-01-03 06:09

    What I did was the following:

    BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance("classpath:beanRefContext.xml");
    BeanFactoryReference parentContextRef = locator.useBeanFactory("ear.context");
    ApplicationContext parentContext = (ApplicationContext) parentContextRef.getFactory();
    childContext.setParent(parentContext);
    

    And guess what, it worked :)

    PS: If anyone knows how to replace the classpath:beanRefContext.xml with an @Configuration class, please let us all know.

提交回复
热议问题