Here is a sample application context injecting the proxy into the target instance:
Code:
<beans>
<bean id="foo" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="targetName" value="fooTarget"/>
<property name="interceptorNames">
<list>
<value>interceptor</value>
</list>
</property>
</bean>
<bean id="interceptor" class="org.springframework.aop.interceptor.SimpleTraceInterceptor">
</bean>
<bean id="fooTarget" class="test.spring.Foo">
<property name="this" ref="foo"/>
</bean>
</beans>
And this is the class:
Code:
package test.spring;
public class Foo {
private Foo thisInstance = this;
public Foo() {}
public Foo getThis() {
return this.thisInstance;
}
public void setThis(Foo thisInstance) {
this.thisInstance = thisInstance;
}
public void op1() {
System.out.println("op1");
}
public void op2() {
System.out.println("op2 calling op1");
getThis().op1();
}
}