Here is a simple example:
The context:
Code:
<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>
...and the code:
Code:
public class Foo {
private Foo thisInstance = this;
public Foo() {}
public Foo getThis() {
return this.thisInstance;
}
public void setThis(Foo pThisInstance) {
this.thisInstance = pThisInstance;
}
public void op1() {
System.out.println("op1");
}
public void op2() {
System.out.println("op2 calling op1");
getThis().op1();
}
}
Note the usage of getThis().op1() instead of just writing this.op1(). By initializing "thisInstance" with "this", the code will continue to work without proxying.
Regards,
Andreas