如何在 Spring 5 中与孩子共享父上下文?
使用 spring 4,我们可以通过locatorFactorySelector
as context-param
<context-param>
<param-name>locatorFactorySelector</param-name>
<param-value>classpath:refFactory.xml</param-value>
</context-param>
从 Spring 5 开始,此支持已被删除。在 Web 上下文中传递父上下文的替代方法是什么?
父上下文的加载基于locatorFactorySelector
被处理于ContextLoader#loadParentContext()
。但他们把它改成了return null
在这个commit.
正如所言javadoc,我认为你可以创建一个新的ContextLoaderListener
并重写此方法以返回父上下文:
public class FooContextLoaderListener extends ContextLoaderListener{
@Override
protected ApplicationContext loadParentContext(ServletContext servletContext) {
//load and return the parent context ......
}
}
然后用这个ContextLoaderListener
启动Spring:
<listener>
<listener-class>org.foo.bar.FooContextLoaderListener</listener-class>
</listener>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)