成都创新互联网站制作重庆分公司

利用监听器怎么对Springbeanid进行唯一校验

利用监听器怎么对Spring bean id进行唯一校验?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站设计、做网站、日照网络推广、成都小程序开发、日照网络营销、日照企业策划、日照品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供日照建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com

1.自定义一个ContextLoader

public class MyContextLoader extends ContextLoader { 
 /** 
  * 设置allowBeanDefinitionOverriding属性为false,spring ioc容器在加载bean的过程中会去判断beanName 是否有重复,. 
    * 如果发现重复的话再根据allowBeanDefinitionOverriding 这个成员变量,. 
    * 如果是false的话则抛出BeanDefinitionStoreException 这个异常,如果为true的话就会覆盖这个bean的定义. 
    * @see org.springframework.web.context.ContextLoader#customizeContext(javax.servlet.ServletContext,    *  org.springframework.web.context.ConfigurableWebApplicationContext)    */   @Override   protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext){    super.customizeContext(servletContext, applicationContext);    XmlWebApplicationContext context = (XmlWebApplicationContext) applicationContext;    //设置allowBeanDefinitionOverriding属性为false    context.setAllowBeanDefinitionOverriding(false);   }   }

2.自定义一个ContextLoaderListener

/** 
 * ClassName:MyContextLoaderListener 
   * Function: 自定义ContextLoaderListener. 
   * Date:  2013-1-18 下午04:12:00 
   * @author chenzhou   * @version   * @since JDK 1.6   */  public class MyContextLoaderListener extends ContextLoaderListener {   @Override   protected ContextLoader createContextLoader(){    return new MyContextLoader();   }  }

3.修改web.xml文件的监听器配置

 
 
 com.chenzhou.examples.erm.util.listener.MyContextLoaderListener 

关于利用监听器怎么对Spring bean id进行唯一校验问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


分享标题:利用监听器怎么对Springbeanid进行唯一校验
当前地址:http://cxhlcq.com/article/jcshec.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部