xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
註解形式是相對於配置xml形式更方便的一種實現依賴注入的方式。
- @Component 是一個泛化的概念,僅僅表示一個組件 (Bean) ,可以作用在任何層次。
- @Service 通常作用在業務層,目前該功能與 @Component 相同。
- @Controller 通常作用在控制層,目前該功能與 @Component 相同。
- @Repository 定義Dao層bean
另,@Resource是按照名稱匹配,作用類似於@Autowired,可以加參數("name")
利用註解讀取配置文件中的屬性:
1,在xml中加入
<util:properties id="accountSecurityConfig" location="classpath:config/AccountSecurityToolsConfig.properties" />
類別 |
說明
|
singleton
|
單實例,整個IOC容器中只有一個Bean實例
|
prototype
|
每次從容器中調用Bean時,都會返回一個新的實例
|
request
|
每次HTTP請求都會創建一個新的Bean
|
session
|
同一個HTTP Session共享一個Bean
|
globalSession
|
同一個全局Session共享一個Bean
|