8 changed files with 101 additions and 70 deletions
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/** |
||||
* |
||||
*/ |
||||
package example.aspects; |
||||
|
||||
import org.aspectj.lang.annotation.Around; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.aspectj.lang.annotation.Before; |
||||
import org.springframework.core.Ordered; |
||||
|
||||
@Aspect("pertarget(execution(* *.getSpouse()))") |
||||
public class PerTargetAspect implements Ordered { |
||||
|
||||
public int count; |
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE; |
||||
|
||||
@Around("execution(int *.getAge())") |
||||
public int returnCountAsAge() { |
||||
return count++; |
||||
} |
||||
|
||||
@Before("execution(void *.set*(int))") |
||||
public void countSetter() { |
||||
++count; |
||||
} |
||||
|
||||
public int getOrder() { |
||||
return this.order; |
||||
} |
||||
|
||||
public void setOrder(int order) { |
||||
this.order = order; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
/** |
||||
* |
||||
*/ |
||||
package example.aspects; |
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint; |
||||
import org.aspectj.lang.annotation.Around; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.aspectj.lang.annotation.Before; |
||||
|
||||
@Aspect |
||||
public class TwoAdviceAspect { |
||||
private int totalCalls; |
||||
|
||||
@Around("execution(* getAge())") |
||||
public int returnCallCount(ProceedingJoinPoint pjp) throws Exception { |
||||
return totalCalls; |
||||
} |
||||
|
||||
@Before("execution(* setAge(int)) && args(newAge)") |
||||
public void countSet(int newAge) throws Exception { |
||||
++totalCalls; |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
/** |
||||
* |
||||
*/ |
||||
package org.springframework.aop.aspectj.annotation; |
||||
|
||||
import org.aspectj.lang.annotation.Around; |
||||
import org.aspectj.lang.annotation.Aspect; |
||||
import org.aspectj.lang.annotation.Before; |
||||
import org.springframework.beans.ITestBean; |
||||
import org.springframework.beans.TestBean; |
||||
|
||||
@Aspect("perthis(execution(* *.getSpouse()))") |
||||
public class PerThisAspect { |
||||
|
||||
public int count; |
||||
|
||||
/** |
||||
* Just to check that this doesn't cause problems with introduction processing |
||||
*/ |
||||
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean(); |
||||
|
||||
@Around("execution(int *.getAge())") |
||||
public int returnCountAsAge() { |
||||
return count++; |
||||
} |
||||
|
||||
@Before("execution(void *.set*(int))") |
||||
public void countSetter() { |
||||
++count; |
||||
} |
||||
} |
Loading…
Reference in new issue