首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

(札记)Spring 中的基本思想 ICO/DI(Dependency Injection)

2012-09-02 
(笔记)Spring 中的基本思想 ICO/DI(Dependency Injection)How to inject the param?There are two way...T

(笔记)Spring 中的基本思想 ICO/DI(Dependency Injection)
How to inject the param?

There are two way...

The first way:
package Apple;

public class Apples {
AppleDao apple;

public AppleDao getApple() {
return apple;
}

public void setApple(AppleDao apple) {
this.apple = apple;
}

public void add(){
apple.addApple(1, "", "", 102);
apple.deleteApple(1);
}


}

Show on ApplicationContext.xml
<beans>
<bean name="apple" ref="apple2"></property>
</bean>


</beans>

The other one:

package Apple;

public class Apples {
AppleDao apple;

public void Apples(AppleDao apple) {
this.apple = apple;
}

public void add(){
apple.addApple(1, "", "", 102);
apple.deleteApple(1);
}


}

Show on ApplicationContext.xml

<bean name="apples" class="Apple.Apples">
<constructor-arg ref="apple2"></constructor-arg></bean>

热点排行