AOP(pointcut)
AOP(pointcut)
- 1.结构
- 2.pom.xml
- 3.advice(通知器)
- 4.anno(注解)
- 5.bean
- 6.service(service层组件)
- 7.spring配置
- 8.测试类
1.结构
2.pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.cskaoyan</groupId><artifactId>demo2-pointcut</artifactId><version>1.0-SNAPSHOT</version><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>6</source><target>6</target></configuration></plugin></plugins></build><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.10.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.2.10.RELEASE</version><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.1</version><scope>test</scope></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.6</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.10.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.4</version><scope>compile</scope></dependency></dependencies></project>
3.advice(通知器)
CountTimeAdvice(用于时间增强,添加时间属性)
@Component
public class CountTimeAdvice implements MethodInterceptor {@Overridepublic Object invoke(MethodInvocation methodInvocation) throws Throwable {long start = System.currentTimeMillis();Object proceed = methodInvocation.proceed();long end = System.currentTimeMillis();System.out.println(methodInvocation.getMethod().getName() + "方法执行时间为:" + (end - start));return proceed;}
}
CustomAdvice(测试委托类执行前后的输出)
proceed的源代码
JoinPoint连接点:代理对象正在执行的方法
@Component
public class CustomAdvice implements MethodInterceptor {@Overridepublic Object invoke(MethodInvocation methodInvocation) throws Throwable {System.out.println("正道的光");Object proceed = methodInvocation.proceed();System.out.println("照在了大地上");return proceed;}
}
4.anno(注解)
CountTime
@Target(ElementType.METHOD) //注解写在哪里
AOP(pointcut)相关推荐
- Java - 你如何理解AOP中的连接点(Joinpoint)、切点(Pointcut)、增强(Advice)、引介(Introduction)、织入(Weaving)、切面(Aspect)这些概念?
分享一个大牛的人工智能教程.零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net a. 连接点(Joinpoint):程序执行的某个特 ...
- 第15章-Spring AOP切点表达式(Pointcut)详解
文章目录 一.概述 二.切点表达式配置 1. 内置配置 2. 注解配置 3. 公共配置 二.切点表达式类型 **`execution`** **`within`** **`this`** **`tar ...
- 十、springboot注解式AOP(@Aspect)统一日志管理
springboot注解式AOP(@Aspect)统一日志管理 简介 AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功 ...
- 手动实现SPring中的AOP(2)
相关名词的解释:通知定义了要织入目标对象的逻辑,以及执行时机.Spring 中对应了 5 种不同类型的通知:· 前置通知(Before):在目标方法执行前,执行通知· 后置通知(After):在目标方 ...
- Spring(十九):Spring AOP(三):切面的优先级、重复使用切入点表达式
背景: 1)指定切面优先级示例:有的时候需要对一个方法指定多个切面,而这多个切面有时又需要按照不同顺序执行,因此,切面执行优先级别指定功能就变得很实用. 2)重复使用切入点表达式:上一篇文章中,定义前 ...
- Spring 源码分析(三) —— AOP(二)Spring AOP 整体架构
2019独角兽企业重金招聘Python工程师标准>>> Spring AOP 架构 先是生成代理对象,然后是拦截器的作用,最后是编织的具体实现.这是AOP实现的三个步 ...
- Spring中的AOP(二)——AOP基本概念和Spring对AOP的支持
AOP的基本概念 AOP从运行的角度考虑程序的流程,提取业务处理过程的切面.AOP面向的是程序运行中的各个步骤,希望以更好的方式来组合业务逻辑的各个步骤.AOP框架并不与特定的代码耦合,AOP框架能处 ...
- 【Spring】AOP(二)自定义来实现AOP
主要是切面定义. 与[Spring]AOP(一)使用Spring的API接口不同的是:这种方式使用自定义来实现AOP,而不是调用Spring的API. 下面直接上例子.(与上一个例子的区别在于,增加了 ...
- SpringBoot+AOP(@Around)
SpringBoot+AOP(@Around) 虽然SpringBoot很方便,可以使我们不太懂原理的情况下都可以轻松的写出一个CRUD的项目,但是SpringBoot的控制反转和依赖注入我们时时刻刻 ...
最新文章
- date比较大小 mybatis_MyBatis版本升级导致OffsetDateTime入参解析异常问题复盘
- android列表时间轴,Android实现列表时间轴
- 高级C语言教程-指针和存储
- 合作开发工具——freeze和pipreqs
- 【ArcGIS风暴】ArcGIS获取线段上等间距的点
- 1009 产生数 2002年NOIP全国联赛普及组
- Spark 之 解决数据倾斜(一)
- java int数组任何数之间间隔不能对于指定数,内付极速排序
- DICM和BMP图像的显示及转换
- 解决 Windows 照片查看器无法显示此图片,因为计算机上的可用内存可能不足
- 三体归零者和盘龙鸿蒙,《三体》中归零者这样的大神级文明已经脱离黑暗森林和猜疑链了吗,为什么?...
- python print用法举例,Python2和Python3中print的用法示例总结
- Android 自定义价格日历控件
- pyqt5版本灭霸响指
- 小米路由器微信连接到服务器,小米路由器怎么设置微信好友免密码直接链接上网?...
- 计算机屏幕出现条纹w7,电脑屏幕出现条纹,教您电脑屏幕出现条纹闪烁怎么解决...
- log4cpp库的使用
- nyoj 一笔画问题
- 【美萍超市管理系统】汉码盘点机无缝对接 金蝶盘点机条码数据采集器智能终端PDA
- 奥斯汀分校 计算机教授 liu,顾海军(吉林大学通信工程学院通信工程系副教授)_百度百科...
热门文章