利用監(jiān)聽器怎么對Spring bean id進行唯一校驗?針對這個問題,這篇文章詳細介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計、做網(wǎng)站、日照網(wǎng)絡(luò)推廣、成都小程序開發(fā)、日照網(wǎng)絡(luò)營銷、日照企業(yè)策劃、日照品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供日照建站搭建服務(wù),24小時服務(wù)熱線:18980820575,官方網(wǎng)址:bm7419.com
1.自定義一個ContextLoader
public class MyContextLoader extends ContextLoader { /** * 設(shè)置allowBeanDefinitionOverriding屬性為false,spring ioc容器在加載bean的過程中會去判斷beanName 是否有重復(fù),. <br/> * 如果發(fā)現(xiàn)重復(fù)的話再根據(jù)allowBeanDefinitionOverriding 這個成員變量,. <br/> * 如果是false的話則拋出BeanDefinitionStoreException 這個異常,如果為true的話就會覆蓋這個bean的定義. <br/> * @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; //設(shè)置allowBeanDefinitionOverriding屬性為false context.setAllowBeanDefinitionOverriding(false); } }
2.自定義一個ContextLoaderListener
/** * ClassName:MyContextLoaderListener <br/> * Function: 自定義ContextLoaderListener. <br/> * Date: 2013-1-18 下午04:12:00 <br/> * @author chenzhou * @version * @since JDK 1.6 */ public class MyContextLoaderListener extends ContextLoaderListener { @Override protected ContextLoader createContextLoader(){ return new MyContextLoader(); } }
3.修改web.xml文件的監(jiān)聽器配置
<!-- 自定義的ContextLoaderListener --> <listener> <listener-class>com.chenzhou.examples.erm.util.listener.MyContextLoaderListener</listener-class> </listener>
關(guān)于利用監(jiān)聽器怎么對Spring bean id進行唯一校驗問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。
分享名稱:利用監(jiān)聽器怎么對Springbeanid進行唯一校驗
分享網(wǎng)址:http://bm7419.com/article42/jcshec.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計公司、微信公眾號、動態(tài)網(wǎng)站、移動網(wǎng)站建設(shè)、App開發(fā)、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)