Spring4 入門案例 註解開發

2021-09-16 21:09:40 字數 826 閱讀 7819

1 新鍵web專案

2 引入jar包---在spring4(3不用)的版本中,除了引入基本的開發包以外,還需要引入aop的包

3.1引入約束spring-framework-4.2.4.release-dist.zip\spring-framework-4.2.4.release\docs\spring-framework-reference\html\xsd-configuguration.html裡面的40.2.8 the context schema

<?xml version="1.0" encoding="utf-8"?>

3.2 配置掃瞄--指定那些包下的類使用ioc註解

4 在類上新增註解

@component(value="userdao")//相當於

5 使用註解方式設定屬性值

屬性如果有set方法,需要將屬性注入的註解新增到set方法。

屬性如果沒有set方法,需要將屬性注入的註解新增屬性上。

spring 4 註解實體

1.建立實體 repository 適用於dao層 service 適用於service controller 適用於web service用於標註業務層元件 controller用於標註控制層元件 如struts中的action repository用於標註資料訪問元件,即dao元件 compon...

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...