摘要: 使用Spring注解注入屬性2009-06-15 17:48 kenshin54 JavaEye博客 我要評(píng)論(0) 字號(hào):T | T本文介紹了使用Spring注解注入屬性的方法。使用注解以前,注入屬性通過(guò)類(lèi)以及配置文件來(lái)實(shí)現(xiàn)。現(xiàn)在,注入屬性可以通過(guò)引入@Autowired注解,或者@Resource,@Qualifier,@PostConstruct,@P...
閱讀全文
posted @
2011-11-21 12:31 hellxoul 閱讀(1661) |
評(píng)論 (0) |
編輯 收藏
原文出自liuxilil
關(guān)鍵字: lazy-init,init-method,destroy-method,depends-on的說(shuō)明
lazy-init,init-method,destroy-method,depends-on的說(shuō)明(這4個(gè)是Spring 1就有的)
- lazy-init是否延遲初始化
- init-method指定初始化方法
- destroy-method指定銷(xiāo)毀方法
- depends-on指定依賴的bean(指定bean的初始化順序)
1 Xml代碼
2 <bean id="bean11" class="test.impl.Bean11" lazy-init="true" init-method="init" destroy-method="destroy" depends-on="bean1"/>
3 <bean id="bean12" class="test.impl.Bean12" lazy-init="false" init-method="init" destroy-method="destroy" depends-on="bean2"/>
4
5 <bean id="bean1" class="test.impl.Bean1" init-method="init" destroy-method="destroy" lazy-init="true"/>
6 <bean id="bean2" class="test.impl.Bean2" init-method="init" destroy-method="destroy" />
說(shuō)明:
1 一個(gè)bean的生命周期是constructor->init->destroy
2 lazy-init決定了bean的初始化時(shí)機(jī) (bean1和bean11在被調(diào)用時(shí),bean2和bean12在ApplicationContext初始化時(shí))
3 depends-on決定了beans的初始化順序(bean11在bean1初始化后,bean22在bean2初始化后)和銷(xiāo)毀順序(bean11在bean1銷(xiāo)毀前,bean22在bean2銷(xiāo)毀前)
posted @
2011-11-21 09:22 hellxoul 閱讀(664) |
評(píng)論 (0) |
編輯 收藏
摘要:
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.spr 閱讀全文
posted @
2011-11-19 15:44 hellxoul 閱讀(51213) |
評(píng)論 (7) |
編輯 收藏
摘要: 在spring2.0之前bean只有2種作用域即:singleton(單例)、non-singleton(也稱(chēng)prototype),Spring2.0以后,增加了session、request、global session三種專(zhuān)用于Web應(yīng)用程序上下文的Bean。因此,默認(rèn)情況下Spring2.0現(xiàn)在有五種類(lèi)型的Bean。當(dāng)然,Spring2.0對(duì)Bean的類(lèi)型的設(shè)計(jì)進(jìn)行了重構(gòu),并設(shè)計(jì)出靈活的Bean類(lèi)型支持,理論上可以有無(wú)數(shù)多種類(lèi)型的Bean,用戶可以根據(jù)自己的需要,增加新的Bean類(lèi)型,滿足實(shí)際應(yīng)用需求。 閱讀全文
posted @
2011-11-19 15:24 hellxoul 閱讀(289) |
評(píng)論 (0) |
編輯 收藏
哈哈,今天開(kāi)始自己的blog
posted @
2011-11-19 15:05 hellxoul 閱讀(127) |
評(píng)論 (0) |
編輯 收藏
摘要: 閱讀全文
posted @
2011-11-19 15:02 hellxoul 閱讀(232) |
評(píng)論 (0) |
編輯 收藏