最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2020年06月17日 08:28:16   作者:TracyDemo  
這篇文章主要介紹了Spring容器初始化及問題解決方案,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

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 id="emp" init-method="initEmp" destroy-method="destroyEmp" lazy-init="false" 
class="com.tracy.bean.Emp" 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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • SpringBoot中Elasticsearch的連接配置原理與使用詳解

    SpringBoot中Elasticsearch的連接配置原理與使用詳解

    Elasticsearch是一種開源的分布式搜索和數(shù)據(jù)分析引擎,它可用于全文搜索、結(jié)構(gòu)化搜索、分析等應(yīng)用場(chǎng)景,本文主要介紹了SpringBoot中Elasticsearch的連接配置原理與使用詳解,感興趣的可以了解一下
    2023-09-09
  • 基于MybatisPlus插件TenantLineInnerInterceptor實(shí)現(xiàn)多租戶功能

    基于MybatisPlus插件TenantLineInnerInterceptor實(shí)現(xiàn)多租戶功能

    這篇文章主要介紹了基于MybatisPlus插件TenantLineInnerInterceptor實(shí)現(xiàn)多租戶功能,需要的朋友可以參考下
    2021-11-11
  • SpringBoot解決mysql連接8小時(shí)問題

    SpringBoot解決mysql連接8小時(shí)問題

    服務(wù)連接mysql數(shù)據(jù)庫,8小時(shí)沒有數(shù)據(jù)庫的操作時(shí)候,數(shù)據(jù)庫會(huì)主動(dòng)斷開連接釋放資源,本文就詳細(xì)的介紹一下解決方法,感興趣的可以了解一下
    2023-08-08
  • java如何生成可變表頭的excel

    java如何生成可變表頭的excel

    這篇文章主要為大家詳細(xì)介紹了java生成可變表頭excel的方法,傳入一個(gè)表頭和數(shù)據(jù),將數(shù)據(jù)導(dǎo)入到excel中,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Java Eclipse中實(shí)現(xiàn)快速替換變量

    Java Eclipse中實(shí)現(xiàn)快速替換變量

    這篇文章主要介紹了Java Eclipse中實(shí)現(xiàn)快速替換變量,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • 詳談jvm線程??臻g內(nèi)存分配位置

    詳談jvm線程??臻g內(nèi)存分配位置

    這篇文章主要介紹了jvm線程棧空間內(nèi)存分配位置,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • springboot斷言異常封裝與統(tǒng)一異常處理實(shí)現(xiàn)代碼

    springboot斷言異常封裝與統(tǒng)一異常處理實(shí)現(xiàn)代碼

    異常處理其實(shí)一直都是項(xiàng)目開發(fā)中的大頭,但關(guān)注異常處理的人一直都特別少,下面這篇文章主要給大家介紹了關(guān)于springboot斷言異常封裝與統(tǒng)一異常處理的相關(guān)資料,需要的朋友可以參考下
    2023-01-01
  • Elasticsearch模糊查詢?cè)敿?xì)介紹

    Elasticsearch模糊查詢?cè)敿?xì)介紹

    這篇文章主要給大家介紹了關(guān)于Elasticsearch模糊查詢的相關(guān)資料,在數(shù)據(jù)庫查詢中模糊查詢是一種強(qiáng)大的技術(shù),可以用來搜索與指定模式匹配的數(shù)據(jù),需要的朋友可以參考下
    2023-09-09
  • SpringBoot配置的加載流程詳細(xì)分析

    SpringBoot配置的加載流程詳細(xì)分析

    了解內(nèi)部原理是為了幫助我們做擴(kuò)展,同時(shí)也是驗(yàn)證了一個(gè)人的學(xué)習(xí)能力,如果你想讓自己的職業(yè)道路更上一層樓,這些底層的東西你是必須要會(huì)的,這篇文章主要介紹了SpringBoot配置的加載流程
    2023-01-01
  • Mybatis/Mybatis-Plus駝峰式命名映射的實(shí)現(xiàn)

    Mybatis/Mybatis-Plus駝峰式命名映射的實(shí)現(xiàn)

    本文主要介紹了Mybatis-Plus駝峰式命名映射的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-07-07

最新評(píng)論

永清县| 赤城县| 九龙县| 广州市| 廊坊市| 麻江县| 宁武县| 嘉善县| 宣汉县| 万年县| 巨野县| 涟水县| 嘉黎县| 辰溪县| 巴彦县| 绵竹市| 陵水| 北票市| 英吉沙县| 平安县| 泌阳县| 如东县| 石棉县| 旺苍县| 普安县| 塔城市| 潞西市| 武川县| 天祝| 如东县| 福海县| 登封市| 龙口市| 攀枝花市| 龙州县| 保康县| 双辽市| 通州区| 顺昌县| 道真| 卢湾区|