接口
public interface FooInterface {
public void printFoo();
public void dummyFoo();
}
实现:
public class FooImpl implements FooInterface {private String s = "init"; public void printFoo() { s = "printFoo"; System.out.println(s); } public void dummyFoo() { System.out.println(s); }
}
配置:
<bean id="foo" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>test.FooInterface</value>
</property>
<property name="target">
<ref bean="fooTarget"/>
</property>
<property name="singleton">
<value>[color=red]false[/color]</value>
</property>
</bean>
<bean id="fooTarget" class="test.FooImpl" singleton="false"></bean>
main调用:
引用
ApplicationContext context = new ClassPathXmlApplicationContext("test/beans.xml");
FooInterface a = (FooInterface)context.getBean("foo");
a.printFoo();
FooInterface b = (FooInterface)context.getBean("foo");
b.dummyFoo();