语法: 

    <aop:config>
<!-- 配置多个切点,&& || ! -->
<aop:pointcut id="pc" expression="execution(public * com.wtas.*.service.*.*(..)) || execution(public * com.wtas.*.*.service.*.*(..)) || execution(public * com.wtas.*.*.*.service.*.*(..))" />
<aop:advisor pointcut-ref="pc" advice-ref="userTxAdvice" />
</aop:config>

其中,&&,||,可以写成and,or,但是需要注意大小写,我在讲||换成大写的OR的时候,不能进行事务控制,不知道是不是区别别大小写的。

1.controller方法:

 @Aspect
@Component
public class TimeAspect { @Around("execution(* com.sea.web.controller.UserController.*(..))")
public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("time aspect start");
//说明:ProceedingJoinPoint 可获取调用的方法的传入参数的值
//如:http:localhost:8080/user/1
//comtroller 方法:public User getInfo(@PathVarable String id)
Object[] args = pjp.getArgs();
for (Object arg : args) {
System.out.println("arg is " + arg); //id 1
}
long start = new Date().getTime();
// 此object 就是条用 方法的返回值 如:User user= UserController.findUser(),
//该方法相当于过滤器中dofilter()方法
Object object = pjp.proceed(); System.out.println("time aspect 耗时:" + (new Date().getTime() - start));
System.out.println("time aspect end");
return object;
} }

//@Around  : 包含以下三种

 Before Advice

代用之前的处理

After Advice

调用之后的处理

Throw Advice

调用的时候抛出的异常处理

execution(* com.sea.web.controller.UserController.*(..))
execution :表示执行
第一个 * :返回值 ;这代表 无论为什么返回值都行
com.sea.web.controller.UserController: 表示那个类
第二个 * :表示方法:类下的所有方法
*(..) :所有方法,任何参数的方法都执行
 

Anotation注解规则:

@Aspect表示注解的类是抽象的服务方法模块;

@Pointcut定义服务的使用规则,也就是服务方法要应用到目标类中哪些方法上。

@Pointcut("execution(*add*(..))") 第一个*表示不论是否有返回值,所有以add开头的方法,不管是否有参数。

private voidaddAddMethod(){};该方法只是注解模式中一个空的方法体,是一个模式化的方法定义结构,该方法不能有返回值,不能有任何参数,也不能对其进行实现。在Advice中要使用该方法名的标识。

Advice注解checkSecurity()方法,表示该方法是具体的服务方法,使用注解的方式,Advice不出现,而是使用上面理论部分提到的使用@After、@Befor、@Throw来表示,同时要在Advice中关联pointcut中定义的规则。

/*
* 拦截器
*/
@Component
@Aspect //切面
public class NamecheckIntercepter {
@Before("execution(public com.icil.entity.Customer com.icil.service.CustomerServiceImpl.*(..))")
public void beforeInteface(){
System.out.println("findCustomerById "+"切面 调用前*******************"); }
@After("execution(public com.icil.entity.Customer com.icil.service.CustomerServiceImpl.*(..))")
public void afterInteface(){
System.out.println("findCustomerById "+"切面 调用后"); } }

spring 的 切片Aspect的更多相关文章

  1. spring 的 切片Aspect 最常用记录方法执行时间

    /** * */ package com.icil.esolution.aspect; import java.util.Date; import org.aspectj.lang.Proceedin ...

  2. Spring Aop实例@Aspect、@Before、@AfterReturning@Around 注解方式配置

    用过spring框架进行开发的人,多多少少会使用过它的AOP功能,都知道有@Before.@Around和@After等advice.最近,为了实现项目中的输出日志和权限控制这两个需求,我也使用到了A ...

  3. spring aop中aspect和advisor的区别

    之前看到spring AOP配置aspect(切面)有两种方式,一种是利用注解的方式配置,一种是利用XML的方式配置. 我们的配置是这样的<aop:aspect>,还有另外一种<ao ...

  4. Spring AOP 的@Aspect

    Spring AOP 的@Aspect   转自:http://blog.csdn.net/tanghw/article/details/3862987 从Spring 2.0开始,可以使用基于sch ...

  5. 【Spring】基于@Aspect的AOP配置

    Spring AOP面向切面编程,可以用来配置事务.做日志.权限验证.在用户请求时做一些处理等等.用@Aspect做一个切面,就可以直接实现. ·   本例演示一个基于@Aspect的小demo 1. ...

  6. Spring Aop实例@Aspect、@Before、@AfterReturning@Around 注解方式配置(转)

    用过spring框架进行开发的人,多多少少会使用过它的AOP功能,都知道有@Before.@Around和@After等advice.最近,为了实现项目中的输出日志和权限控制这两个需求,我也使用到了A ...

  7. Spring切面编程Aspect之@Before和@Around用法

    查看dao层使用的sql import java.util.Arrays; import org.apache.commons.lang.ArrayUtils; import org.aspectj. ...

  8. spring boot使用@Aspect记录日志(请求参数,响应结果)

  9. Spring Aspect 获取请求参数

    切片(Aspect)也就是Spring AOP 实现Aspect的主要步骤: 1.在哪里切入 .在哪个方法起作用 .什么时候起作用 2.起作用的时候执行什么处理逻辑 下面是代码实现 /** * 切片A ...

随机推荐

  1. python入门20180717-迭代器、生成器和协程

    迭代器.生成器和协程 python中任意的对象,只要它定义了可以返回一个迭代器的__iter__方法,或者支持下标索引的_getitem_方法,那么它就是一个可迭代对象. 可迭代的对象不一定就是迭代器 ...

  2. 树莓派的媒体播放软件omxplayer

    树莓派中的CPU性能较差,而GPU较强大.omxplayer是专门针对树莓派的GPU的播放器.( made by Edgar (gimli) Hucek from the XBMC/Kodi proj ...

  3. BAT调用7z压缩程序

    @echo offset zip=C:\Program Files\7-Zip\7z.exeset timestamp=%date:~6,4%-%date:~0,2%-%date:~3,2%set d ...

  4. 【转】第六章、Linux 的文件权限与目录配置

    原文网址:http://vbird.dic.ksu.edu.tw/linux_basic/0210filepermission.php 最近更新日期:2009/08/18 Linux最优秀的地方之一, ...

  5. Server对象,HttpServerUtility类,获取服务器信息

    在Asp.net WebForm中,Server对象是HttpServerUtility类的实例.看下图: 而在Asp.net MVC中,Server对象是HttpServerUtilityBase对 ...

  6. C语言sscanf用法解析与正则表达式支持

    最近学习算法和输入输出用到的基本知识,首先是我自己写的一份代码参考和学习了很多资源 后面会给出参考资料,他们写得更加详细,正则表达式的支持确实是一大亮点所在 #include<iostream& ...

  7. centos7下svn的安装与配置

    1.环境 centos7 2.安装svnyum -y install subversion 3.配置 建立版本库目录mkdir /www/svndata svnserve -d -r /www/svn ...

  8. Windows下 YOLOv3配置教程(YOLOv3项VS2013平台迁移的方法)

    https://blog.csdn.net/maweifei/article/details/81150489

  9. Linq快速入门——扩展方法

    Linq为我们提供了许多扩展方法,方便我们对数据源进行操作(Where,Select...).即使你不了解算法,也能使用Linq当回牛人.扩展方法本质并不是什么高深的技术,说白了就是一个Static静 ...

  10. js实现动态球形标签云

    HTML 原文演示地址:http://www.17sucai.com/pins/demoshow/8108 <!DOCTYPE html PUBLIC "-//W3C//DTD XHT ...