<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="use" class="com.appform.Use">
<property name="g">
<ref local="job" />
</property>
</bean>
<bean id="job" class="com.appform.JobManager" />
</beans>
public interface GeneralInterface{
public void test();
}
public class JobManager implements GeneralInterface {
//把那个接口实现一下
public void test() {
System.out.println("test()");
}
public class Use implements MianInterface {
private GeneralInterface g;
//设值进来
public void setG(GeneralInterface g) {
this.g = g;
public void execute() {
g.test();
}
}
main 函数
Use p = (Use) ctx.getBean("use");
p.execute();
可以得到结果,假如我要是再有个类实现GeneralInterface接口
然后我要把两个类的 execute()方法都要执行,该怎么弄
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="use" class="com.appform.Use">
<property name="g">
<ref local="job" />
</property>
</bean>
<bean id="job" class="com.appform.JobManager" />
</beans>
public interface GeneralInterface{
public void test();
}
public class JobManager implements GeneralInterface {
//把那个接口实现一下
public void test() {
System.out.println("test()");
}
public class Use implements MianInterface {
private GeneralInterface g;
//设值进来
public void setG(GeneralInterface g) {
this.g = g;
public void execute() {
g.test();
}
}
main 函数
Use p = (Use) ctx.getBean("use");
p.execute();
可以得到结果,假如我要是再有个类实现GeneralInterface接口
然后我要把两个类的 execute()方法都要执行,该怎么弄














