<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. java开发---关于ORA00604和ORA12705

    MyEclipse和oracle连接中出现的一个问题: 在使用工具连接orcale数据库时报了这两个异常  ORA-00604和ORA12705 ; 查找问题原因: 大概猜测是与字符集有关系 , 确认 ...

  2. c++小游戏——彩票

    #include <cstdlib> #include <iostream> #include <cstdio> #include <cmath> #i ...

  3. NOIP2018初赛题解 提高组

  4. 深入理解 JavaScript 单例模式 (Singleton Pattern)

    概念 单例模式,也叫单子模式,是一种常用的软件设计模式.在应用这个模式时,单例对象的类必须保证只有一个实例存在. 核心:确保只有一个实例,并提供全局访问. 实现思路 一个类能返回对象一个引用(永远是同 ...

  5. TensorFlow笔记-初识

    深度学习: 转换编程的思维(和传统的机器学习的编程方式不太一样) 测试链接 TensorFlow的安装 CPU版本: 只支持程序在CPU上计算/运算,默认运行就是CPU上运行 卸载: pip unin ...

  6. [小米OJ] 10. 爬楼梯

    dp 另: 小米oj上的测试样例是错的 ; ) function solution(line) { if (line == 0) return 0; if (line == 1) return 1; ...

  7. python课堂整理12---递归

    一.递归特性 1.必须有一个明确的结束条件 2.每次进入更深一层递归时,问题规模相比上次递归都应有所减少 3.递归效率不高,递归层次过多会导致栈溢出(在计算机中,函数调用是通过栈(stack)这种数据 ...

  8. 任何类型的数据都向String转型

    String从其定义上发现首字母大写,所以此为一个类,属于引用数据类型,但是此类属于系统的类. (1)String像普通变量一样直接通过复制的方式进行声明.字符串使用双引号括起来.两个字符串使用&qu ...

  9. SpringBoot日志相关

    SpringBoot使用的是SLF4j当门面,Logback当实现完成 日志级别 数字越大,级别越高,框架只会输出大于等于当前日志级别的信息 ERROR 40 WARN 30 INFO 20 DEBU ...

  10. ajax性能优化

    ajax性能优化 例: 模块: A B C D 开销: 50%  3% 25%   22% 如果我们优化B就如同那些那些只执行一次的代码,性能·提高不到哪里去:反之,我们去优化A,比如去优化它的循环, ...