亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Spring容器初始化及問題解決方案

瀏覽:3日期:2023-09-02 09:34:37

1.Spring bean組件 ”默認為單例模式scope=“singleton, 運行JavaApplication容器啟動時自動創建對象

scope=“prototype”為多例模式,請求條件下才創建對象

2beans組件 里面default-init-method初始化方法加載,范圍比較大,當沒有此方法時不會報錯,default-destroy-method銷毀方法,default-lazy-init=“true/false” 對象延時實例化

3.bean組件里面init-method初始化無此方法,會報錯, destroy-method銷毀方法,lazy-init=“true/false” 延時實例化

注意:

1.銷毀方法對scope=“prototype”多例模式無效

2.AbstractApplicationContext可以關閉容器,可以調用close()方法,關閉容器,調用銷毀方法

3.對象延時實例化對多例模式沒有意義。

XML

<?xml version='1.0' encoding='UTF-8'?><beans xmlns='http://www.springframework.org/schema/beans' xmlns:context='http://www.springframework.org/schema/context' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:aop='http://www.springframework.org/schema/aop' xmlns:tx='http://www.springframework.org/schema/tx' xmlns:p='http://www.springframework.org/schema/p' xmlns:util='http://www.springframework.org/schema/util' xmlns:jdbc='http://www.springframework.org/schema/jdbc' xmlns:cache='http://www.springframework.org/schema/cache' xsi:schemaLocation=' http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd' default-init-method='initEmp' default-destroy-method='destroyEmp' default-lazy-init='true'> <bean init-method='initEmp' destroy-method='destroyEmp' lazy-init='false' scope='singleton' ></bean> </beans>

Test方法

//bean組件的默認方式 @Test public void beanInitTest() { AbstractApplicationContext appContext=new ClassPathXmlApplicationContext('com/tracy/xml/bean-init-destroy.xml'); ApplicationContext app=new ClassPathXmlApplicationContext('com/tracy/xml/bean-init-destroy.xml'); Emp emp=app.getBean('emp',Emp.class); System.out.print(emp); appContext.close(); }

通過構造完成初始bean屬性,可以通過初始化完成

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 亚洲人成网国产最新在线 | 午夜宅男宅女看在线观看 | 一级毛片一级片 | 麻豆传媒小视频 | 亚洲欧美精品一区天堂久久 | 成人羞羞免费视频 | 国自产拍在线视频天天更新 | 免费视频日本xvideos | 国产男女性做爽歪歪爱视频 | 91热久久免费精品99 | 伊人啪啪 | 亚洲午夜久久久久久91 | 国产亚洲日本 | 网址大全在线免费观看 | 黄色篇 | 经典三级一区二区三区视频 | 中文日韩欧美 | 特一级黄 | 人体大胆做受免费视频 | 国产在线91区精品 | 国产精品亚洲综合久久 | 国产福利不卡视频 | 香蕉爱爱视频 | 欧美成人h版影片在线观看 欧美成人h版影院在线播放 | 国产一区二区在免费观看 | 波多野结衣黑人系列在线观看 | 亚洲视频在线观看网址 | 亚洲 欧美 日韩 在线 香蕉 | 亚洲依依成人精品 | 尤物在线视频观看 | 九九免费高清在线观看视频 | 久久九九精品视频 | 亚洲综合区 | 精品视频在线免费播放 | 综合第一页 | 靠逼久久 | 久久一er精这里有精品 | 欧美日韩综合一区 | 成人18xxxx网站 | 欧美一区二区三区免费高 | 精品欧美亚洲韩国日本久久 |