Sharing parent spring context with child in spring 5

拜拜、爱过 提交于 2021-02-08 10:28:22

问题


How to share parent context with child in spring 5?

Using spring 4, we could pass locatorFactorySelector as context-param

<context-param>
    <param-name>locatorFactorySelector</param-name>
    <param-value>classpath:refFactory.xml</param-value>
</context-param>

This support is removed from Spring 5 onward. What is the alternative to pass the parent context in web context?


回答1:


The loading of the parent context based on locatorFactorySelector were handled at ContextLoader#loadParentContext(). But they changed it to return null in this commit.

As said by the javadoc , I think you can create a new ContextLoaderListener and override this method to return the parent context:

public class FooContextLoaderListener extends ContextLoaderListener{

    @Override
    protected ApplicationContext loadParentContext(ServletContext servletContext) {
        //load and return the parent context ......
    }

}

Then use this ContextLoaderListener to start up Spring :

<listener>
    <listener-class>org.foo.bar.FooContextLoaderListener</listener-class>
</listener>


来源:https://stackoverflow.com/questions/54085902/sharing-parent-spring-context-with-child-in-spring-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!