Java 防止重写bean的bean定义
我知道我们可以通过以下方式禁用SpringBean的重载:Java 防止重写bean的bean定义,java,spring,Java,Spring,我知道我们可以通过以下方式禁用SpringBean的重载: GenericApplicationContext.setAllowBeanDefinitionOverriding(boolean b) 不过,我认为WebApvestTror上下文不是程序加载的,而是通过Web.xml文件加载的。那么,我如何防止在WebApplicationContext中过度使用Springbean呢?。在web.xml中: <context-param> <param-name>
GenericApplicationContext.setAllowBeanDefinitionOverriding(boolean b)
不过,我认为WebApvestTror上下文不是程序加载的,而是通过Web.xml文件加载的。那么,我如何防止在WebApplicationContext中过度使用Springbean呢?
。在web.xml中:<context-param>
<param-name>contextClass</param-name>
<param-value>my.package.MyWebApplicationContext</param-value>
</context-param>
使用Servlet ContextListener并获取对上下文的引用,然后调用上面的方法。
public class MyWebApplicationContext extends XmlWebApplicationContext {
public MyWebApplicationContext() {
super();
this.setAllowBeanDefinitionOverriding(false);
}
}