/** * Create a new AspectJProxyFactory. * <p>Will proxy all interfaces that the given target implements. * @param target the target object to be proxied */ public AspectJProxyFactory(Object target) { Assert.notNull(target, "Target object must not be null"); setInterfaces(ClassUtils.getAllInterfaces(target)); setTarget(target); }
@Test public void testProgrammaticProxyCreation() { ITestBean testBean = new TestBean(); AspectJProxyFactory factory = new AspectJProxyFactory(); factory.setTarget(testBean); CounterAspect myCounterAspect = new CounterAspect(); factory.addAspect(myCounterAspect); ITestBean proxyTestBean = factory.getProxy(); assertTrue("Expected a proxy", proxyTestBean instanceof Advised); proxyTestBean.setAge(20); assertEquals("Programmatically created proxy shouldn't match bean()", 0, myCounterAspect.count); }
/** * Create a new AspectJProxyFactory. * <p>Will proxy all interfaces that the given target implements. * @param target the target object to be proxied */ public AspectJProxyFactory(Object target) { Assert.notNull(target, "Target object must not be null"); setInterfaces(ClassUtils.getAllInterfaces(target)); setTarget(target); }
/** * Create a new AspectJProxyFactory. * <p>Will proxy all interfaces that the given target implements. * @param target the target object to be proxied */ public AspectJProxyFactory(Object target) { Assert.notNull(target, "Target object must not be null"); setInterfaces(ClassUtils.getAllInterfaces(target)); setTarget(target); }
class Example { final Foo foo; Example(Foo original) { AspectJProxyFactory factory = new AspectJProxyFactory(); factory.setTarget(original); factory.addAspect(FooAspect.class); foo = (Foo) factory.getProxy(); } @Aspect static class FooAspect { @Before("execution(Foo.doBar())") Object beforeDoBar() { // My own activity } }