Hi, I would like to trace bar(), but only if it gets called from foo(). Unfortunately only if I call bar() directly it will get intercepted. Could somebody help me how to get this working?
Thank you very much in advance.
robert
Code:package test; import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestAOP { public void foo(){ System.err.println( "foo calling bar" ); bar(); } public void bar(){ System.err.println( "bar called" ); } public static void main(String[] args){ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "/application-context.xml" ); TestAOP aop = (TestAOP)ctx.getBean("testAOPAdvised"); aop.bar(); aop.foo(); } } <bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor"> </bean> <bean id="testAOP" class="test.TestAOP"/> <bean id="testAOPAdvised" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="proxyTargetClass"> <value>true</value> </property> <property name="target"> <ref local="testAOP" /> </property> <property name="interceptorNames"> <list> <value>debugInterceptor</value> </list> </property> </bean>So before the last "bar called" I would like to have something like---console output----
Debug interceptor: count=1 invocation=[Invocation: method=[public void test.TestAOP.bar()] args=[Ljava.lang.Object;@11eb199] target is of class [test.TestAOP]]
bar called
Debug interceptor: next returned
Debug interceptor: count=2 invocation=[Invocation: method=[public void test.TestAOP.foo()] args=[Ljava.lang.Object;@11eb199] target is of class [test.TestAOP]]
foo calling bar
bar called
Debug interceptor: next returned
Debug interceptor: count=3 invocation=[Invocation: method=[public void test.TestAOP.bar()] args=[Ljava.lang.Object;@11eb199] target is of class [test.TestAOP]]


Reply With Quote