<bean id="drink_01" name="drink_02" scope="singleton"
lazy-init="true"
init-method="init" destroy-method="destroy"
class="com.test.pojo.Drink" />
scope屬性
bean標簽中添加scope屬性,設(shè)置bean對應(yīng)對象生成規(guī)則.
scope = “singleton”
單例,默認值,適用于實際開發(fā)中的絕大部分情況.
scope=“prototype”
多例,適用于struts2中的action配置
lazy-init屬性
注意: 只對單例有效,設(shè)置scope="singleton"時測試
延時創(chuàng)建屬性.
lazy-init=“false” 默認值,不延遲創(chuàng)建,即在啟動時候就創(chuàng)建對象.
lazy-init=“true” 延遲初始化,在用到對象的時候才會創(chuàng)建對象.文章來源:http://www.zghlxwxcb.cn/news/detail-674132.html
初始化/銷毀
在Drink類中添加初始化方法和銷毀方法(名稱自定義):文章來源地址http://www.zghlxwxcb.cn/news/detail-674132.html
public void init() {
System.out.println("Drink的初始化方法");
}
public void destroy() {
System.out.println("Drink的銷毀方法");
}
到了這里,關(guān)于javaee spring配置文件bean標簽詳解的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!