[color=red][b]注解方式的面向切面编程[/b][/color]
spring对AOP的支持(采用Annotation的方式)
1、spring依赖库
* SPRING_HOME/dist/spring.jar
* SPRING_HOME/lib/commons-logging.jar
* SPRING_HOME/lib/log4j-1.2.14.jar
* SPRING_HOME/lib/aspectj/*.jar
2、模块化横切关注点,采用@Aspect定义切面
3、在Aspect中定义Pointcut和Advice
4、启用AspectJ对Annotation的支持,参见applicationContext.xml
注意:采用Annotation定义Pointcut,Pointcut的方法是不被执行的,它存在的目的
仅仅是为了Adivce重用Pointcut的定义
AOP中的术语:
* Cross cutting concern
* Aspect--[color=red]Aspect就是要切入的类。即,SecurityHandler.java由Advice和Pointcut组成[/color]
* Advice --[color=red]切入类SecurityHandler.java中的切入方法checkSecurity()[/color]
* Pointcut --[color=red]Pointcut内容是一个表达式,来描述织入到哪些对象上的哪些方法(订阅感兴趣Joinpoint)例如:@Pointcut("execution(* add*(..)) || execution(* del*(..))")[/color]
* Jointpoint
* Weave--[color=red]应用到目标对象上的过程叫织入[/color]
* target Object --[color=red]真正的实现类UserManagerImpl.java[/color]
* Proxy --[color=red]Spring的AOP是使用JDK的动态Proxy实现的[/color]
* Introduction
spring对AOP的支持(采用Annotation的方式)
1、spring依赖库
* SPRING_HOME/dist/spring.jar
* SPRING_HOME/lib/commons-logging.jar
* SPRING_HOME/lib/log4j-1.2.14.jar
* SPRING_HOME/lib/aspectj/*.jar
2、模块化横切关注点,采用@Aspect定义切面
3、在Aspect中定义Pointcut和Advice
4、启用AspectJ对Annotation的支持,参见applicationContext.xml
注意:采用Annotation定义Pointcut,Pointcut的方法是不被执行的,它存在的目的
仅仅是为了Adivce重用Pointcut的定义
AOP中的术语:
* Cross cutting concern
* Aspect--[color=red]Aspect就是要切入的类。即,SecurityHandler.java由Advice和Pointcut组成[/color]
* Advice --[color=red]切入类SecurityHandler.java中的切入方法checkSecurity()[/color]
* Pointcut --[color=red]Pointcut内容是一个表达式,来描述织入到哪些对象上的哪些方法(订阅感兴趣Joinpoint)例如:@Pointcut("execution(* add*(..)) || execution(* del*(..))")[/color]
* Jointpoint
* Weave--[color=red]应用到目标对象上的过程叫织入[/color]
* target Object --[color=red]真正的实现类UserManagerImpl.java[/color]
* Proxy --[color=red]Spring的AOP是使用JDK的动态Proxy实现的[/color]
* Introduction