Dheeraj Joshi
Dheeraj Joshi

Reputation: 3147

Sharing parent spring context with child in spring 5

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?

Upvotes: 2

Views: 2297

Answers (1)

Ken Chan
Ken Chan

Reputation: 90447

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>

Upvotes: 3

Related Questions