学习记录
来源:互联网 发布:网站源码有什么用 编辑:程序博客网 时间:2024/06/14 16:43
@AspectJ的风格类似纯java注解的普通java类
Spring可以使用AspectJ来做切入点解析
AOP的运行时仍旧是纯的Spring AOP,对AspectJ的编译器或者织入无依赖性
@Aspect注解是不能够通过类路径自动检测发现的,所以需要配合使用@Component注释或者在xml配置bean
一个类中的@Aspect注解标识它为一个切面,并且将自己从自动代理中排除
@Pointcut注解,方法返回类型必须为void
Supported Pointcut Designators
execution 匹配方法执行的连接点
within 限定匹配特定类型的连接点
this 匹配特定链接点的bean引用是指定类型的实例的限制
target 限定匹配特点链接点的目标对象参数是指定类型的实例
args 限定匹配特点链接点的参数是给定类型的实例
@target 限定匹配特点链接点的类执行对象的具有给定类型的注解
@args 限定匹配特定连接点实际传入参数的类型具有给定类型的注解
@within 限定匹配到内具有给定的注释类型的连接点
@annotation 限定匹配特定连接点的主体具有给定的注解
示例
xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <context:component-scan base-package="com.imooc.aop.aspectj"/> <aop:aspectj-autoproxy></aop:aspectj-autoproxy> </beans>
@Component@Aspectpublic class MoocAspect {@Pointcut("execution(* com.imooc.aop.aspectj.biz.*Biz.*(..))")public void pointcut() {}@Pointcut("within(com.imooc.aop.aspectj.biz.*)")public void bizPointcut() {}}
定义良好的pointcuts
AspectJ是编译期的AOP
检查代码并匹配连接点与切入点的代价是昂贵的
一个好的切入点应该包括以下几点:
选择特定类型的连接点,如:execution,get,set,call,handler
确定连接点范围,如:within,withcode
匹配上下文信息,如:this,target,@annotation
0 0
- --学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 学习记录
- 十分钟搞定pandas
- 119-epoll(触发模式)
- 软件测试的基础理论
- mysql workbench中PK,NN,UQ,BIN,UN,ZF,AI字段类型标识说明
- Qt Graphics入门小例以及实现场景中相关项拖拽功能总结.
- 学习记录
- 记一次openstack的部署过程
- Transfer-Encoding:chunked 返回数据过长导致中文乱码
- UVA 10048 Flyod算法
- 算法导论 第六章 堆排序
- POJ3164-Command Network
- 哈工大LTP编译使用
- Android之使用HttpURLConnection连接网络
- hdoj 1027 Ignatius and the Princess II (全排列)