AOPプロキシをプログラム的に生成する
org.springframework.aop.framework.ProxyFactoryを使えば、AOPプロキシをプログラムで簡単に生成できます。
※1.X系から提供されているやり方。
ProxyFactory factory = new ProxyFactory(new SimplePojo()); factory.addInterface(Pojo.class); // For use CGLIB Proxy(default JDK dynamic proxy) // factory.setProxyTargetClass(true); factory.setExposeProxy(true); // AOPContextに公開するかどうか PerformanceMonitorInterceptor Interceptor = new PerformanceMonitorInterceptor(); Interceptor.setUseDynamicLogger(true); factory.addAdvice(Interceptor); Pojo pojo = (Pojo) factory.getProxy(); pojo.foo();
参考