Spring註解開發簡要步驟

2022-06-12 10:24:10 字數 586 閱讀 4108

spring-aop-4.2.4.release.jar

2、匯入約束(最後兩行)

<

beans

xmlns

=""xmlns:xsi

=""xmlns:contexnt

=""xsi:schemalocation

="/spring-beans.xsd

/spring-context-2.5.xsd"

>

3、指定注釋自動掃瞄的包,自動注入包中有註解的類

<

contexnt:component-scan

base-package

="org.helloworld"

>

contexnt:component-scan

>

4、在掃瞄的類上加入注釋標籤

@component、@service等等

5、注入引用

@autowired   自動注釋

@resource(name = "user") 指定名稱

備註:也可以xml配置和注釋混合使用

Spring註解開發

spring註解開發 dao層用的註解 repository service層的註解 service controller表現層的註解 controller 以上的三個註解都是用 componment新增三個衍生的註解 屬性依賴注入 value的屬性注入 value wwtmy love 注入的是屬...

spring註解開發

第一步,設定xml約束檔案 第一步,設定xml約束檔案 xmlns xsi xmlns context xsi schemalocation spring beans.xsd spring context.xsd 第二步,定義bean 除了 component外,spring提供了3個功能基本和 c...

Spring註解開發

在spring4之後,要使用註解開發,但是必須保證aop的包存在 使用註解必須保證匯入context約束增加註解的支援 xmlns xmlns xsi xmlns context xsi schemalocation spring beans.xsd spring context.xsd conte...