// Continue on. Invoke the real method or constructor. InvocationResponse rsp = invocation.invokeNext(); System.out.println(Leaving + message); return rsp; } }
运行例子2 [code]POJO类将扩展一点,增加get()和set()方法。 public class POJO { public POJO() {} public void helloWorld() { System.out.println(Hello World!); }
private int counter = 0;
public int getCounter() { return counter; } public void setCounter(int val) { counter = val; } public static void main(String[] args) { POJO pojo = new POJO(); pojo.helloWorld(); pojo.setCounter(32); System.out.println(counter is: + pojo.getCounter()); } } TracingInterceptor将拦截对main(),POJO()和helloWorld()调用。输出应该看起来如下: Entering constructor: public POJO() Leaving constructor: public POJO() Entering method: helloWorld Hello World! Leaving method: helloWorld [/code]