您的位置:首页 > 编程语言 > ASP

SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-003-Spring对AOP支持情况的介绍

2016-03-03 15:08 751 查看
一、

不同的Aop框架在支持aspect何时、如何织入到目标中是不一样的。如AspectJ和Jboss支持在构造函数和field被修改时织入,但spring不支持,spring只支持一般method的织入。spring通过以下四种方式支持AOP:

 Classic Spring proxy-based AOP
 Pure- POJO aspects
 @AspectJ annotation-driven aspects
 Injected AspectJ aspects (available in all versions of Spring)

前三种是Spring自己的对AOP的实现,即运行时织入,第四种是直接调用AspectJ。

二、Sping的AOP的几个特点

1.Advice都是写在java中

2.SPRING ADVISES OBJECTS AT RUNTIME

In Spring, aspects are woven into Spring-managed beans at runtime by wrapping them with a proxy class. As illustrated in figure 4.3, the proxy class poses as the target bean,intercepting advised method calls and forwarding those calls to the target bean.Between the time when the proxy intercepts the method call and the time when it invokes the target bean’s method, the proxy performs the aspect logic.

Spring doesn’t create a proxied object until that proxied bean is needed by the application. If you’re using an ApplicationContext , the proxied objects will be created when it loads all the beans from the BeanFactory . Because Spring creates proxies at runtime, you don’t need a special compiler to weave aspects in Spring’s AOP



3.SPRING ONLY SUPPORTS METHOD JOIN POINTS

Because it’s based on dynamic proxies, Spring only supports method join points.If you find yourself in need of more than method interception, you’ll want to complement Spring AOP with AspectJ.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: