spring aop参数传递
spring aop参数传递
使用示例
HelloService
public interface HelloService {String hello();String hello(String name);String hello(String name, Integer age);
}
HelloServiceImpl
@Service
public class HelloServiceImpl implements HelloService {@Overridepublic String hello() {return "hello";}@Overridepublic String hello(String name) {return "hello " + name;}@Overridepublic String hello(String name, Integer age) {return "hello " + name + " " + age;}
}
CustomAspect
@Aspect
@Component
public class CustomAspect {@Pointcut("execution(* *.hello(..))")public void fun(){}@Pointcut("execution(* *.hello(String)) && args(name))")public void fun2(String name){}@Pointcut("execution(* *.hello(String,..)) && args(name))")public void fun3(String name){}@Pointcut("execution(* *.hello(String,Integer)) && args(name,age)")public void fun4(String name, Integer age){}@Before("fun()")public void before(JoinPoint joinPoint){System.out.print("before ==> ");process(joinPoint);}@Before("fun2(name)")public void before2(JoinPoint joinPoint,String name){System.out.print("before2 ==> " + name + " ==> ");process(joinPoint);}@Before("fun3(name)")public void after3(JoinPoint joinPoint,String name){System.out.print("after3 ==> "+ name + " ==> ");process(joinPoint);}@After("fun4(name,age)")public void after4(JoinPoint joinPoint, String name, Integer age){System.out.print("after4 ==> "+ name + " " +age + " ==> ");process(joinPoint);}public void process(JoinPoint joinPoint){MethodSignature signature =(MethodSignature) joinPoint.getSignature();Method method = signature.getMethod();System.out.println(method.getDeclaringClass().getName()+"."+method.getName()+":被调用");}
}
HelloController
@RestController
public class HelloController {@Resourceprivate HelloService helloService;@RequestMapping("/hello")public String hello(){return helloService.hello();}@RequestMapping("/hello2")public String hello2(){return helloService.hello("瓜田李下");}@RequestMapping("/hello3")public String hello3(){return helloService.hello("瓜田李下",20);}
}
使用示例
localhost:8080/hello,控制台输出:
before ==> com.example.demo.controller.HelloController.hello:被调用
before ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
localhost:8080/hello2,控制台输出:
after3 ==> 瓜田李下 ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
before ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
before2 ==> 瓜田李下 ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
localhost:8080/hello3,控制台输出:
before ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
after4 ==> 瓜田李下 20 ==> com.example.demo.service.impl.HelloServiceImpl.hello:被调用
spring aop参数传递相关推荐
- Spring 学习——Spring AOP——AOP配置篇Advice(有参数传递)
声明通知Advice 配置方式(以前置通知为例子) 方式一 <aop:config> <aop:aspect id="ikAspectAop" ref=" ...
- Spring学习总结(4)——Spring AOP教程
2019独角兽企业重金招聘Python工程师标准>>> 一.概念 AOP(Aspect Oriented Programming):面向切面编程. 面向切面编程(也叫面向方面编程), ...
- Spring——AOP
AOP AOP概述 AOP(Aspect-Oriented Programming,面向切面编程):是一种新的方法论,是对传统 OOP(Object-Oriented Programming,面向对象 ...
- 基于 Annotation 拦截的 Spring AOP 权限验证方法
余 清, 软件工程师, IBM 简介: 使用 Annotation 可以非常方便的根据用户的不同角色,分配访问 Java 方法的权限.在 Java Web 开发中,使用这种方法,可以提高系统的松耦合度 ...
- Spring AOP详解(http://sishuok.com/forum/posts/list/281.html)
三6.5 AspectJ切入点语法详解 6.5.1 Spring AOP支持的AspectJ切入点指示符 切入点指示符用来指示切入点表达式目的,,在Spring AOP中目前只有执行方法这一个连接 ...
- Spring AOP知识点简介
文章目录 1.什么是AOP 1.1.AOP术语 1.2.AOP框架 2.动态代理 2.1.JDK动态代理 2.2.CGLIB动态代理 3.基于代理类的AOP实现 3.1.Spring的通知类型 3.2 ...
- spring aop组件_安全性中的Spring AOP –通过方面控制UI组件的创建
spring aop组件 以下文章将显示在我参与的一个项目中,我们如何使用Spring的AOP来介绍一些与安全性相关的功能. 这样的概念是,为了使用户能够看到某些UI组件,他需要具有一定级别的安全特权 ...
- 安全性中的Spring AOP –通过方面控制UI组件的创建
以下文章将显示在我参与的一个项目中,我们如何使用Spring的AOP来介绍一些与安全性相关的功能. 这样的概念是为了使用户能够看到一些UI组件,他需要具有一定级别的安全特权. 如果不满足该要求,则不会 ...
- Spring AOP看这个就够了
AOP简介 AOP(Aspect-Oriented Programming,面向切面编程):是一种新的方法论,是对传统 OOP(Object-Oriented Programming,面向对象编程)的 ...
最新文章
- v$sysstat表解释
- android简单歌词,Yuan-LrcView
- Qt Creator制作动画
- php文件上传指定路径,php上传文件到指定文件夹
- mysql -b -e_MySQL 的B+树索引.
- 学信网:研究生云复试平台快速搭建上线
- QQ号终于可以当传家宝了!没车没房的,就留几个游戏账号给儿子吧?
- WSS3.0安装后,系统资源消耗这么大
- 单片机万年历阴阳历c语言,单片机 阴历阳历c算法 万年历
- fork函数与execve函数
- 华为USG6000V防火墙学习
- echarts 文本标签配置、label文字样式
- 阿里云对象存储OSS简介和使用
- php gd ttf,linux gd php TTF字体
- 【R实验.8】方差分析
- Linux安装GaussDB数据库图文,GaussDB 100 on Linux安装手册
- 虚树-树上动态规划的利器
- 当六月的雨,带了些许思念的时候,记忆的扉页,被忧伤一一翻阅
- A - Eddy‘s AC难题(C语言)
- ES自定义Analyzer扩展IK分词