springtester
Sep 1st, 2004, 06:30 AM
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
package test;
import org.springframework.context.support.ClassPathXmlAp plicationContext;
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.DebugIntercept or">
</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>
---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
So before the last "bar called" I would like to have something like
Debug interceptor: count=3 invocation=[Invocation: method=[public void test.TestAOP.bar()] args=[Ljava.lang.Object;@11eb199] target is of class [test.TestAOP]]
Thank you very much in advance.
robert
package test;
import org.springframework.context.support.ClassPathXmlAp plicationContext;
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.DebugIntercept or">
</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>
---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
So before the last "bar called" I would like to have something like
Debug interceptor: count=3 invocation=[Invocation: method=[public void test.TestAOP.bar()] args=[Ljava.lang.Object;@11eb199] target is of class [test.TestAOP]]