(笔记)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" class="Apple.AppleDaoImpl"></bean>
<bean name="apple2" class="Apple.AppleDaoImple"></bean>

<bean name="apples" class="Apple.Apples">
<property 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>

你可能感兴趣的:(spring,apple,xml)