语法: 

    <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. java8 流操作 好文网址

    api 各方法详解(很不错!) http://blog.51cto.com/turnsole/2093185 api 各方法 简介: https://www.cnblogs.com/guguli/p/ ...

  2. VPC/VM/VBOX安装GHOST版的无法启动系统

    本人最近在安装一些公司的虚拟机,方便开发使用,不用每次都安装几个小时的装机和安装软件,但是本次却遇到了一点问题,虚拟机安装完成后一直无法进入系统,只有一个光标在黑色的屏幕上一闪一闪的,也没有任何错误提 ...

  3. python 网络编程要点

    From http://www.zhihu.com/question/19854853 Python网络编程是一个很大的范畴,个人感觉需要掌握的点有:1. 如何使用Python来创建socket, 如 ...

  4. linux挂载SD卡

    (1)通过#fdisk -l命令确认板子上的linux系统是否识别SD卡 MP805M板子插入SD卡后显示 SD30 slot is without WPmmc1: new high speed SD ...

  5. 【转】每天一个linux命令(48):watch命令

    原文网址:http://www.cnblogs.com/peida/archive/2012/12/31/2840241.html watch是一个非常实用的命令,基本所有的Linux发行版都带有这个 ...

  6. Eclipse相对路径

    Eclipse将java源文件存于src文件夹,而编译生成的class文件存于bin目录下,故以下代码输出的结果为false public class FileTest { public static ...

  7. 大快hadoop安装包下载与平台监控参数说明

    前阶段用了差不多两周的时间把DKhadoop的运行环境搭建以及安装的各个操作都介绍了一遍.关于DKhadoop安装包下载也只是顺带说了一下,但好像大快搜索的服务器在更新,新的下载页面还不好用!有好些朋 ...

  8. asp.net Repeater使用例子,包括分页

    <style type="text/css">    .tab{border-collapse:collapse; margin:0 auto;}    .tab th ...

  9. Centos替换默认源

    将默认的国外源替换为国内的网易的源 参考帮助文档:http://mirrors.163.com/.help/centos.html 查看本机版本:cat /etc/redhat-release 先安装 ...

  10. gc之六--Minor GC、Major GC、Full GC以及Mixed GC之间的区别

    目录: GC之一--GC 的算法分析.垃圾收集器.内存分配策略介绍 GC之二--GC日志分析(jdk1.8)整理中 GC之三--GC 触发Full GC执行的情况及应对策略 gc之四--Minor G ...