<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
package cn.fff.test.aop;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; @Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface TrackTime {
String param() default "";
}
package cn.fff.test.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component; @Aspect
@Component
public class TrackTimeAspect { @Pointcut("execution(* cn.fff.test.GirlService.aopDemo(..))")
public void aopDemo() {} @Before("TrackTimeAspect.aopDemo()")
public void before(JoinPoint joinPoint) {
System.out.println(" -------------> Before Aspect ");
System.out.println(" -------------> before execution of " + joinPoint);
} /*@Around("@annotation(trackTime)")
public Object around(ProceedingJoinPoint joinPoint, TrackTime trackTime) throws Throwable {
Object result = null;
long startTime = System.currentTimeMillis();
result = joinPoint.proceed();
long timeTaken = System.currentTimeMillis() - startTime;
System.out.println(" -------------> Time Taken by " + joinPoint + " with param[" + trackTime.param() + "] is " + timeTaken);
return result;
}*/ @Around("@annotation(trackTime)")
public void around(ProceedingJoinPoint joinPoint, TrackTime trackTime) throws Throwable {
System.out.println("玩地地道道的");
joinPoint.proceed(); System.out.println(" -------------> Time Taken by " + joinPoint + " with param[" + trackTime.param() + "] is "); }
}
package cn.fff.test;

import cn.fff.test.aop.TrackTime;
import org.springframework.stereotype.Service; @Service
public class GirlService { @TrackTime(param = "myService")
public void getAge(Integer id){ Integer age =id;
System.out.println("环绕通知");
if (age <= 10) {
throw new GirlException(ResultEnum.PRIMARY_SCHOOL);
} if (age < 16) {
throw new GirlException(ResultEnum.MIDDLE_SCHOLL);
}
} public void aopDemo() {
System.out.println("defdfdfdfddfdf");
} }

springboot中springAOP的使用的更多相关文章

  1. SpringBoot中yaml配置对象

    转载请在页首注明作者与出处 一:前言 YAML可以代替传统的xx.properties文件,但是它支持声明map,数组,list,字符串,boolean值,数值,NULL,日期,基本满足开发过程中的所 ...

  2. 如何在SpringBoot中使用JSP ?但强烈不推荐,果断改Themeleaf吧

    做WEB项目,一定都用过JSP这个大牌.Spring MVC里面也可以很方便的将JSP与一个View关联起来,使用还是非常方便的.当你从一个传统的Spring MVC项目转入一个Spring Boot ...

  3. springboot中swaggerUI的使用

    demo地址:demo-swagger-springboot springboot中swaggerUI的使用 1.pom文件中添加swagger依赖 2.从github项目中下载swaggerUI 然 ...

  4. spring-boot+mybatis开发实战:如何在spring-boot中使用myabtis持久层框架

    前言: 本项目基于maven构建,使用mybatis-spring-boot作为spring-boot项目的持久层框架 spring-boot中使用mybatis持久层框架与原spring项目使用方式 ...

  5. 由浅入深学习springboot中使用redis

    很多时候,我们会在springboot中配置redis,但是就那么几个配置就配好了,没办法知道为什么,这里就详细的讲解一下 这里假设已经成功创建了一个springboot项目. redis连接工厂类 ...

  6. Springboot中使用AOP统一处理Web请求日志

    title: Springboot中使用AOP统一处理Web请求日志 date: 2017-04-26 16:30:48 tags: ['Spring Boot','AOP'] categories: ...

  7. SpringBoot 中常用注解

    本篇博文将介绍几种SpringBoot 中常用注解 其中,各注解的作用为: @PathVaribale 获取url中的数据 @RequestParam 获取请求参数的值 @GetMapping 组合注 ...

  8. SpringBoot中关于Mybatis使用的三个问题

    SpringBoot中关于Mybatis使用的三个问题 转载请注明源地址:http://www.cnblogs.com/funnyzpc/p/8495453.html 原本是要讲讲PostgreSQL ...

  9. 在SpringBoot中配置aop

    前言 aop作为spring的一个强大的功能经常被使用,aop的应用场景有很多,但是实际的应用还是需要根据实际的业务来进行实现.这里就以打印日志作为例子,在SpringBoot中配置aop 已经加入我 ...

随机推荐

  1. Git常用命令--了解这些就够了

    <div class="show-content-free"> <blockquote> Csdn 将本地工程push到远程 方式一: 建立本地仓库 git ...

  2. response对象和request对象详解

    request方法列举:request.getAuthType() // 获取保护servlet的认证方案名(BASIC或SSL),未受保护的servlet返回的就是nullrequest.getCh ...

  3. Linux命令大全(简)

    rm--删除文件和目录   -i 删除一个已存在的文件前,提示用户进行确认.   -r 递归的删除目录. mkdir--创建目录 cp--复制文件和目录   -i 在覆盖一个已存在的目录前,提示用户进 ...

  4. linux初学者-磁盘配额篇

    linux初学者-磁盘配额篇 在使用磁盘时,只要有权限,不管什么用户都可以在其中写入数据,但是如果是多人在一个磁盘中写入数据,就会出现争议,如果一个用户将磁盘空间用完,那么其他人无法再使用.如下图所示 ...

  5. Appium+python自动化(二十四)- 白素贞千年等一回许仙 - 元素等待(超详解)

    简介 许仙小时候最喜欢吃又甜又软的汤圆了,一次一颗汤圆落入西湖,被一条小白蛇衔走了.十几年后,一位身着白衣.有青衣丫鬟相伴的美丽女子与许仙相识了,她叫白娘子.白娘子聪明又善良,两个人很快走到了一起.靠 ...

  6. CentOS7 修改PATH环境变量的方法

    vim /etc/profile 添加: PATH=/root/.config/composer/vendor/bin:$PATH 保存,退出,运行: source /etc/profile 检查: ...

  7. 2019牛客暑期多校训练营(第四场)J-free

    >传送门< 题意:给你n个城市,m条道路,经过每一条要花费这条路的代价,现给你k个机会,使得最多k条路的代价为0,问从起点s到终点t花费的最少代价 思路:分层图最短路经典裸题 方法一 Co ...

  8. IO流的Properties集合,序列化流与反序列化流,打印流及commons-IO

    内容介绍 Properties集合 序列化流与反序列化流 打印流 commons-IO Properties类 Properties类介绍 Properties 类表示了一个持久的属性集.Proper ...

  9. go 学习笔记之工作空间

    搭建好 Go 的基本环境后,现在可以正式开始 Go 语言的学习之旅,初学时建议在默认的 GOPATH 工作空间规范编写代码,基本目录结构大概是这个样子. . |-- bin | `-- hello.e ...

  10. WPF:window设置单一开启

    方法一: Window window = new Window();window.ShowDialog; 方法二: 设置一个判断窗口打开状态的全局控制变量         private bool i ...