av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

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

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

1.Spring bean組件 ”默認(rèn)為單例模式scope=“singleton, 運(yùn)行JavaApplication容器啟動(dòng)時(shí)自動(dòng)創(chuàng)建對(duì)象

scope=“prototype”為多例模式,請(qǐng)求條件下才創(chuàng)建對(duì)象

2beans組件 里面default-init-method初始化方法加載,范圍比較大,當(dāng)沒有此方法時(shí)不會(huì)報(bào)錯(cuò),default-destroy-method銷毀方法,default-lazy-init=“true/false” 對(duì)象延時(shí)實(shí)例化

3.bean組件里面init-method初始化無此方法,會(huì)報(bào)錯(cuò), destroy-method銷毀方法,lazy-init=“true/false” 延時(shí)實(shí)例化

注意:

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

2.AbstractApplicationContext可以關(guān)閉容器,可以調(diào)用close()方法,關(guān)閉容器,調(diào)用銷毀方法

3.對(duì)象延時(shí)實(shí)例化對(duì)多例模式?jīng)]有意義。

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組件的默認(rèn)方式 @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(); }

通過構(gòu)造完成初始bean屬性,可以通過初始化完成

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 久久免费精品 | 91福利在线观看视频 | 自拍偷拍第一页 | 亚洲欧美国产一区二区三区 | 午夜视频在线免费观看 | 亚洲成人一区二区 | 国产精品综合色区在线观看 | 一区二区三区视频 | 久久精品国产一区二区三区不卡 | 日韩毛片免费看 | 91视频网址 | 天天干天天爱天天 | 亚洲国产精品久久久久婷婷老年 | 精品国产99 | 亚洲91| 国产福利在线视频 | 精品中文字幕在线观看 | 亚洲女人的天堂 | 黄色一级大片在线免费看产 | 日韩中文字幕一区 | 久久国产精品-国产精品 | 一区二区免费看 | 亚洲精品一区二区三区蜜桃久 | 亚洲精品欧美一区二区三区 | 欧美日韩视频在线第一区 | 亚洲欧美中文日韩在线v日本 | 久久一本| 91精品国产欧美一区二区 | 一区二区福利视频 | 国产99久久久国产精品下药 | 久久久国产网站 | 一区二区三区精品视频 | 蜜桃黄网 | 国产精品久久久免费 | 国产色在线 | 久久精品国产99国产精品 | 91成人午夜性a一级毛片 | 涩涩导航 | 亚洲一区国产 | 日本午夜免费福利视频 | 福利片在线 |