亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

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

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

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

注意:

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

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

3.對象延時實(shí)例化對多例模式?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屬性,可以通過初始化完成

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Maven中plugins和pluginManagement區(qū)別小結(jié)

    Maven中plugins和pluginManagement區(qū)別小結(jié)

    pluginManagement是表示插件聲明,plugins就是直接引入一個plugin,本文主要介紹了Maven中plugins和pluginManagement區(qū)別小結(jié),具有一定的參考價值,感興趣的可以了解一下
    2024-06-06
  • windows下 jdk1.7安裝教程圖解

    windows下 jdk1.7安裝教程圖解

    java編程的初學(xué)者在開始編碼前都會遇到一個難題,那就是jdk1.7環(huán)境變量配置怎么操作,怎么安裝,針對這個難題,小編特地為大家整理相關(guān)教程,不了解的朋友可以前往查看使用
    2018-05-05
  • Spring Boot如何優(yōu)化內(nèi)嵌的Tomcat示例詳解

    Spring Boot如何優(yōu)化內(nèi)嵌的Tomcat示例詳解

    spring boot默認(rèn)web程序啟用tomcat內(nèi)嵌容器,監(jiān)聽8080端口,下面這篇文章主要給大家介紹了關(guān)于Spring Boot如何優(yōu)化內(nèi)嵌Tomcat的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-09-09
  • java中JSONArray互相轉(zhuǎn)換List的實(shí)現(xiàn)

    java中JSONArray互相轉(zhuǎn)換List的實(shí)現(xiàn)

    本文主要介紹了java中JSONArray互相轉(zhuǎn)換List的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • Spring?Boot?3.1中整合Spring?Security和Keycloak的方法

    Spring?Boot?3.1中整合Spring?Security和Keycloak的方法

    本文介紹在最新的SpringBoot3.1版本之下,如何將Keycloak和Spring?Security一起跑起來,文中結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2023-06-06
  • Java實(shí)用工具之StringJoiner詳解

    Java實(shí)用工具之StringJoiner詳解

    這篇文章主要介紹了Java實(shí)用工具之StringJoiner詳解,文中有非常詳細(xì)的代碼示例,對正在學(xué)習(xí)java的小伙伴們有很好地幫助,需要的朋友可以參考下
    2021-05-05
  • 關(guān)于SpringBoot微服務(wù)發(fā)布與部署的三種方式

    關(guān)于SpringBoot微服務(wù)發(fā)布與部署的三種方式

    SpringBoot 框架只提供了一套基于可執(zhí)行 jar 包(executable jar)格式的標(biāo)準(zhǔn)發(fā)布形式,但并沒有對部署做過多的界定,而且為了簡化可執(zhí)行 jar 包的生成,SpringBoot 提供了相應(yīng)的 Maven 項(xiàng)目插件,需要的朋友可以參考下
    2023-05-05
  • SpringBoot自動裝配之@Enable深入講解

    SpringBoot自動裝配之@Enable深入講解

    這篇文章主要介紹了SpringBoot自動裝配之@Enable,SpringBoot中提供了很多Enable開頭的注解,這些注解都是用于動態(tài)啟用某些功能的。而其底層原理是使用@Import注?解導(dǎo)入一些配置類,實(shí)現(xiàn)Bean的動態(tài)加載
    2023-01-01
  • IDEA2020如何打開Run Dashboard的方法步驟

    IDEA2020如何打開Run Dashboard的方法步驟

    這篇文章主要介紹了IDEA2020如何打開Run Dashboard的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • java編程之基于SpringBoot框架實(shí)現(xiàn)掃碼登錄

    java編程之基于SpringBoot框架實(shí)現(xiàn)掃碼登錄

    本文將介紹基于SpringBoot + Vue + Android實(shí)現(xiàn)的掃碼登錄demo的總體思路,文中附含詳細(xì)示例代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2021-09-09

最新評論