AOP注解

  1. 1. xml 方式配置
  2. <aop:config>  
  3.     <aop:aspectrefaop:aspectref="aspectDef">  
  4.         <aop:pointcutidaop:pointcutid="pointcut1"expression="execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))"/>  
  5.         <aop:before pointcut-ref="pointcut1" method="beforeAdvice" />  
  6.     </aop:aspect>  
  7. </aop:config>  
  8. 2. 注解方式 
  9. @Component  
  10. @Aspect  
  11. public class AspectDef {  
  12.     //@Pointcut("execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))")  
  13.     //@Pointcut("within(com.test.spring.aop.pointcutexp..*)")  
  14.     //@Pointcut("this(com.test.spring.aop.pointcutexp.Intf)")  
  15.     //@Pointcut("target(com.test.spring.aop.pointcutexp.Intf)")  
  16.     //@Pointcut("@within(org.springframework.transaction.annotation.Transactional)")  
  17.     //@Pointcut("@annotation(org.springframework.transaction.annotation.Transactional)")  
  18.     @Pointcut("args(String)")  
  19.     public void pointcut1() {  
  20.     }  
  21.     @Before(value = "pointcut1()")  
  22.     public void beforeAdvice() {  
  23.         System.out.println("pointcut1 @Before...");  
  24.     }  

猜你喜欢

转载自ln-software.iteye.com/blog/2369578