Bean的屬性注入

2021-09-14 00:06:27 字數 1344 閱讀 5353

集合實體類

public

class

collectiondemo

//set方法注入

@test

public

void

test2()

//set方法注入

@test

public

void

test3()

//測試集合屬性注入---list

@test

public

void

test4()

//測試集合屬性注入---set

@test

public

void

test5()

//測試集合屬性注入---map

@test

public

void

test6()

// 測試集合屬性注入---properties

@test

public

void

test7()

p/c命名空間

"dog"

class

="pc.dog"

p:name

="小白"

p:color

="白色"

>

bean

>

"dog1"

class

="pc.dog"

c:name

="小黑"

c:color

="黑色"

>

bean

>

"person"

class

="pc.person"

p:name

="小王"

p:dog-ref

="dog1"

p:age

="20"

>

bean

>

"person1"

class

="pc.person"

>

name

="name"

value

="#"

>

property

>

name

="dog"

value

="#"

>

property

>

name

="age"

value

="#"

>

property

>

bean

>

spring 依賴注入bean的屬性

對於類成員變數,spring支援建構函式注入,屬性setter方法注入 0.domain類 public class student public student string name,int age public string getname public void setname string...

spring為物件 bean 屬性賦值(注入)

public class people public int getid public void setid int id public string getname public void setname string name public setgetsets public void sets...

注入巢狀Bean

如果某個bean所依賴的bean不想被spring容器直接訪問,可以使用巢狀bean。元素用來定義巢狀bean,巢狀bean只對巢狀它的外部bean有效,spring容器無法直接訪問巢狀bean,因此定義巢狀bean時無須指定id屬性。package dependencyinjection publ...