/** * Adds a declare parents pointcut - spr5307 * @author Andy Clement * @since 3.0 */ @Aspect class MakeAnnotatedTypeModifiable extends AbstractMakeModifiable { @DeclareParents(value = "(@org.springframework.aop.aspectj.annotation.Measured *)", defaultImpl = DefaultLockable.class) public static Lockable mixin; }
@Aspect class DummyAspect { @Around("execution(* setAge(int))") public Object test(ProceedingJoinPoint pjp) throws Throwable { return pjp.proceed(); } }
@Around("getAge()") public int preventExecution(ProceedingJoinPoint pjp) { return 666; } }
@Before("execution(void *.set*(int))") public void countSetter() { ++count; } }
@After("execution(* java.lang.Runnable.*(..))") public void after(JoinPoint joinPoint) { count++; } }
@Aspect public static class ExceptionAspect { private final Exception ex; public ExceptionAspect(Exception ex) { this.ex = ex; } @Before("execution(* getAge())") public void throwException() throws Exception { throw ex; } }
/** * Adds a declare parents pointcut. * @author Rod Johnson * @since 2.0 */ @Aspect class MakeITestBeanModifiable extends AbstractMakeModifiable { @DeclareParents(value = "org.springframework.tests.sample.beans.ITestBean+", defaultImpl=ModifiableImpl.class) public static MutableModifiable mixin; }
@Around("getAge()") public int preventExecution(ProceedingJoinPoint pjp) { return 666; } }
@Before("execution(void *.*(..))") public void countAnythingVoid() { ++count; } }
@Aspect public static class LogAllAspect { @Before("execution(void *.additionalMethod(*))") public void log(JoinPoint jp) { System.out.println("Before " + jp.getSignature().getName()); } }
@Before("this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsAtAspectJTests.TestInterface) " + "&& target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsAtAspectJTests.TestImpl)") public void incrementThisAsInterfaceAndTargetAsClassCounter() { thisAsInterfaceAndTargetAsClassCounter++; }
@Aspect class AtAspectJAnnotationBindingTestAspect { @Around("execution(* *(..)) && @annotation(testAnn)") public Object doWithAnnotation(ProceedingJoinPoint pjp, TestAnnotation testAnn) throws Throwable { String annValue = testAnn.value(); Object result = pjp.proceed(); return (result instanceof String ? annValue + " " + result : result); } }
@Before("this(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsAtAspectJTests.TestInterface) " + "&& target(org.springframework.aop.aspectj.ThisAndTargetSelectionOnlyPointcutsAtAspectJTests.TestInterface)") public void incrementThisAsInterfaceAndTargetAsInterfaceCounter() { thisAsInterfaceAndTargetAsInterfaceCounter++; }
@Aspect static class AnAspect { @Before("execution(* org.springframework.tests.sample.beans.TestBean.*(..))") public void advice() { } }
@Aspect public static class LoggingAspect { @Before("@args(org.springframework.context.annotation.EnableAspectJAutoProxyTests.Loggable))") public void loggingBeginByAtArgs() { } }
@Aspect public static class NamedPointcutAspectWithoutFQN { @Pointcut("execution(* getAge())") public void getAge() { } @Around("getAge()") public int changeReturnValue(ProceedingJoinPoint pjp) { return -1; } }
@Aspect public static class MyAspect { private final AtomicInteger count = new AtomicInteger(0); @org.aspectj.lang.annotation.Before("execution(* scheduled())") public void checkTransaction() { this.count.incrementAndGet(); } }
@Aspect class CounterAspect { int count; @Before("execution(* set*(..)) && bean(testBean1)") public void increment1ForAnonymousPointcut() { count++; } }
@Aspect static class CounterAtAspectJAspect { @Around(value="execution(* org.springframework.tests.sample.beans.TestBean.*(..)) and this(bean) and args(argument)", argNames="bean,argument") public void increment(ProceedingJoinPoint pjp, TestBean bean, Object argument) throws Throwable { pjp.proceed(); } } }
@Aspect static class NameChangingAspect { @Before("execution(* org.springframework.tests.sample.beans.TestBean.absquatulate(..)) && target(testBean)") public void touchBean(TestBean testBean) { testBean.setName("advisedName"); } }