Spring 裝配Bean 基於註解

2021-08-08 18:58:56 字數 950 閱讀 9055

註解:就是乙個類,使用@註解名稱

開發中:使用註解 取代 xml配置檔案。

@component取代

@component(「id」) 取代

2.web開發,提供3個@component註解衍生註解(功能一樣)取代

@repository :dao層

@service:service層

@controller:web層

3.依賴注入 ,給私有字段設定,也可以給setter方法設定

普通值:@value(「」)

引用值:

方式1:按照【型別】注入

@autowired

方式2:按照【名稱】注入1

@autowired

@qualifier(「名稱」)

方式3:按照【名稱】注入2

@resource(「名稱」)

4.生命週期

初始化:@postconstruct

銷毀:@predestroy

5.作用域

@scope(「prototype」) 多例

註解使用前提,新增命名空間,讓spring掃瞄含有註解類

Spring 裝配Bean 基於註解

註解 就是乙個類,使用 註解名稱 開發中 使用註解 取代 xml配置檔案 註解使用前提,新增命名空間,讓spring掃瞄含有註解類 在xml檔案中加這段 讓其掃瞄類中的所有註解 1.component 把普通pojo例項化到spring容器中,用來取代 bean class component id...

Spring 裝配bean基於註解

裝配bean基於註解 一 用註解取代 xml 配置檔案 component component id 取代 bean id class web開發中,提供3個 component註解衍生註解 功能一樣 取代 bean class 依賴注入,給私有字段設定,也可以給setter方法設定 生命週期 初始...

Spring 裝配Bean 基於註解

1.component取代 component id 取代 2.web開發,提供3個 component註解衍生註解 功能一樣 取代 repository dao層 service service層 controller web層 3.依賴注入 給私有字段設定,也可以給setter方法設定 普通值 ...