<bean id="panda" class="com.zyiz.netmon.Panda" autowire="autodetect" /> <bean id="kungfu" class="com.zyiz.netmon.KungFu" > <property name="name" value="Tai Ji" /> </bean>
package com.zyiz.netmon; public class Panda { private KungFu kungfu; public Panda(KungFu kungfu) { System.out.println("autowiring by constructor"); this.kungfu = kungfu; } public KungFu getKungfu() { return kungfu; } public void setKungfu(KungFu kungfu) { System.out.println("autowiring by type"); this.kungfu = kungfu; } //... }
输出
autowiring by type Person [kungfu=Language [name=Tai Ji]]
package com.zyiz.netmon; public class Panda { private KungFu kungfu; public KungFu getKungfu() { return kungfu; } public void setKungfu(KungFu kungfu) { System.out.println("autowiring by type"); this.kungfu = kungfu; } //... }
输出
autowiring by type Person [kungfu=Language [name=Tai Ji]]