第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Spring 一二事(4) - 單例

標(biāo)簽:
Java

spring bean配置后再默认情况下是单例的,如果需要配置可以选择 prototype, request, session和global session

在配置spring mvc的action时,可以对action使用 prototype

<!-- singleton: 默认单例 prototype: 多例 request ,session和global session: 只适用于web程序 -->
    <bean id="scope_prototype" class="com.lee.spring005.scope.Scope"
        scope="prototype"></bean>

    <!-- destroy-method 一般在数据源的时候用到,关闭容易后就销毁连接 -->
    <bean id="initDestory" class="com.lee.spring006.init_destory.InitDestory"
        init-method="init" destroy-method="destory"></bean>

bean的创建销毁过程:

package com.lee.spring006.init_destory;

public class InitDestory {

    public InitDestory() {
        System.out.println("InitDestory() ");
    }

    public void hello() {
        System.out.println("Hello InitDestory!");
    }

    public void init() {
        System.out.println("init");
    }

    public void destory() {
        System.out.println("destory");
    }
}

测试:

@Test
    public void testInitDestory() {

        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        InitDestory initDestory = (InitDestory)context.getBean("initDestory");
        initDestory.hello();

        ClassPathXmlApplicationContext app = (ClassPathXmlApplicationContext)context;
        app.close();
    }
點(diǎn)擊查看更多內(nèi)容
“小禮物走一走,來(lái)慕課關(guān)注我”
贊賞支持
風(fēng)間影月說(shuō) 去圍觀
創(chuàng)業(yè)公司技術(shù)總監(jiān), 10年+開(kāi)發(fā)和技術(shù)管理經(jīng)驗(yàn)。SUN認(rèn)證SCJP、PMP、MCP認(rèn)證。主要從事后端技術(shù)和架構(gòu)領(lǐng)域,有豐富的電商平臺(tái)與物流平臺(tái)核心系統(tǒng)的架構(gòu)設(shè)計(jì)和開(kāi)發(fā)經(jīng)驗(yàn)。
評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消