1.AspectJ的概念

  @AspectJ类似于Java注解的普通Java类

  Spring可以使用AspectJ来做切入点解析

  AOP的运行时仍旧是纯的Spring AOP,对AspectJ的编译器或者织入无依赖性.

2.配置方式

  注解方式 -- @Configuration

              @EnableAspectJAutoProxy

              任何拥有@Aspect注解的bean都将被Spring自动识别并应用

              注释的类可以有方法和字段,他们也可以有切入点(pointcut),通知(Advice)和引入(introduction)声明

              @Aspect注解不能够通过类路径自动检测发现,需要配合使用@Component注释或者在XML配置bean

  xml文件方式

           --<aop:aspectj-autoproxy/>

           

3.ASpectJ为编译期的AOP,检查代码并匹配连接点与切入点的代价昂贵

  好的切入点包括

    --选择特定类型的连接点(execution/get/set/call/handler)

    --确认连接点范围(within/withincode)

    --匹配上下文信息(this/target/@annotation)

    

4.Around advice

  使用@Around注释来声明,通知方法的第一个参数必须是ProcessdingJoinPoint类型

  再通知内部调用processdingjoinpoint的proceed()方法会引导至真正的方法,传入一个Object[]对象,数组中的值将被作为参数传递给方法

  

5. * 使用execution表达式

* 使用已经定义表达式的方法名 --@Before("pointcut()")

@AfterReturning(pointcut="implPointcut()",returning="args")

@AfterThrowing(pointcut="pointcut()",throwing="e")

@After("pointcut()")

      @Pointcut("execution(* com.aspectj.impl.*Impl.*(..))")

      @Pointcut("within(com.aspectj.impl.*)")

      

6.Advice扩展

  1>给advice传递参数 -- 方法的参数可以是任何类的对象

    在@before时+&&args(account,..)

    定义注解传参

        @Before("pointcut()&&@annotation(methodValue)")

        public void beforeWithAnnotation(Methodvalue methodValue)

    SpringAOp可以处理泛型类的声明和使用方法的参数

    通知和切入点注解有一个额外的"argNames"属性,它可以用来指定所注解的方法的参数名

    --如果第一参数时JoinPoint,ProceedingJoinPoint,JoinPoint.StaticPart,那么可以忽略它 -- -- ,argNames="bean,auditable,.."

  2>Introductions

    允许一个切面声明一个通知对象实现指定接口,并且提供了一个接口实现类来代表这些对象

    introduction使用@DeclareParents进行注解,这个注解用来定义匹配的类型拥有一个新的parent

  3>切面实例化模型 -- 高级主题

    "perthis"切面通过指定@Aspect注解perthis子句实现

    每个独立的service对象执行时都会创建一个切面实例

    service对象的每个方法在第一次执行的时候创建切面实例,切面在service对象失效的同时失效

    

http://blog.csdn.net/jacxuan/article/details/53454819

AcpectJ注释方式配置AOP的更多相关文章

  1. 基于配置文件的方式配置AOP

    之前说的都是通过注释的方式配置,接下来说说如何使用配置文件配置AOP 还是原来的代码,去掉所有注释,接下来配置最基本的几个bean. 然后使用<aop:config>标签进行配置,然后配切 ...

  2. xml的方式配置AOP:Aspect Oriented Programming

    在某些类中, 什么时机, 做什么事情 切入点(point-cut): 在某些类中(Class<?>[] itfc = new Class<?>[] { IStudentServ ...

  3. Spring_基于配置文件的方式配置AOP

    applicationContext-xml.xml <?xml version="1.0" encoding="UTF-8"?> <bean ...

  4. 22Spring基于配置文件的方式配置AOP

    直接看代码: package com.cn.spring.aop.impl; //加减乘除的接口类 public interface ArithmeticCalculator { int add(in ...

  5. Annotation方式配置AOP

    package com.xk.spring.kp04_aop.aop.s02_annotation; public interface IStudentService { public void sa ...

  6. spring-AOP框架(基于配置文件的方式配置AOP)

    .xml: ref-指向,order-指定优先级

  7. SSH深度历险(十) AOP原理及相关概念学习+AspectJ注解方式配置spring AOP

    AOP(Aspect Oriented Programming),是面向切面编程的技术.AOP基于IoC基础,是对OOP的有益补充. AOP之所以能得到广泛应用,主要是因为它将应用系统拆分分了2个部分 ...

  8. Spring(二十):Spring AOP(四):基于配置文件的方式来配置 AOP

    基于配置文件的方式来配置 AOP 前边三个章节<Spring(十七):Spring AOP(一):简介>.<Spring(十八):Spring AOP(二):通知(前置.后置.返回. ...

  9. spring aop注解方式与xml方式配置

    注解方式 applicationContext.xml 加入下面配置 <!--Spring Aop 启用自动代理注解 --> <aop:aspectj-autoproxy proxy ...

随机推荐

  1. How to install VIB on VMware ESXi

    What is VIB? A vib is  vSphere Installation Bundle. To make it more detailed, one can look at the vS ...

  2. Share single RDM between multiple VM's in ESX

    1.Create a VM01 on esx01,Create a VM02 on esx02 2.Create the RDM on your VM01 (using the virtual, no ...

  3. iframe操作(跨域解决等)

    note:当页面内嵌入一个iframe实际上是在dom上新建了一个新的完整的window对象 iframe中取得主窗体 window.top (顶级窗口的window对象) window.parent ...

  4. 无法安装MVC3,一直卡在vs10-kb2483190

    原文发布时间为:2011-05-15 -- 来源于本人的百度文章 [由搬家工具导入] 无法安装MVC3,一直卡在vs10-kb2483190 解决方案: 1、用winrar 解压 MVC3安装文件 2 ...

  5. 1.Openstack-环境安装

    Centos7 OpenStack环境安装 Ifcofnig vim命令 Centos7最小化安装后如没有ifconfig vim命令,执行: 1 yum install -y net-tools v ...

  6. 使用log4j2分离系统日志与业务日志

    前一篇文章介绍了log4j2 扩展日志级别,支持将系统日志与业务处理日志拆分,现在介绍一下通过日志级别将系统日志与业务日志分类,要达到这个目的很容易,只需要配置一下log4j的xml文件: <? ...

  7. 虚拟机linux 挂载windows共享目录 给linux的nginx服务器使用

    mount -t cifs -o username=administrator,password=xxxx,file_mode=0777,dir_mode=0777 //192.168.xx.xxx/ ...

  8. nginx安全日志分析脚本的编写

    https://blog.csdn.net/nextdoor6/article/details/51914966

  9. SQL Server 预编译执行SQLs

    问题描述: MVC5项目,利用执行sql的方式获取数据,但是在利用预编译执行的时候报错了,字段XXXwhich was not supplied. 其实就是这个参数传了个null导致的.在传参数之前做 ...

  10. 使用keytool生成ssl证书

    使用keytool生成ssl证书 在项目中由于要使用https访问项目,然后了解到jdk有一个自带的工具keytool可以用来生成ssl证书,从而可以通过https进行访问. 使用keytool生成s ...