首页
统计
壁纸
关于我
Search
1
Mysql delete from table 和 truncate table 的区别
782 阅读
2
Spring AOP 术语说明
704 阅读
3
MySQL事务隔离级别
653 阅读
4
Java引用类型:强引用、软引用、弱引用、软引用
589 阅读
5
Linux开启BBR
11 阅读
随笔
时政
技术
登录
Search
标签搜索
Java
Mysql
Xiaodong
累计撰写
6
篇文章
累计收到
2
条评论
首页
栏目
随笔
时政
技术
页面
统计
壁纸
关于我
搜索到
1
篇与
的结果
2020-07-16
Spring AOP 术语说明
举个例子一个aspect切面classpublic class Logging { /** * This is the method which I would like to execute * before a selected method execution. */ public void beforeAdvice() { System.out.println("Going to setup student profile."); } /** * This is the method which I would like to execute * after a selected method execution. */ public void afterAdvice() { System.out.println("Student profile has been setup."); } /** * This is the method which I would like to execute * when any method returns. */ public void afterReturningAdvice(Object retVal) { System.out.println("Returning:" + retVal.toString()); } /** * This is the method which I would like to execute * if there is an exception raised. */ public void AfterThrowingAdvice(IllegalArgumentException ex) { System.out.println("There has been an exception: " + ex.toString()); } }SpringAOP.xml配置<bean id="student" class="com.seeyon.SpringBean.aop.Student" p:name="yangyu" p:age="27"></bean> <bean id="logging" class="com.seeyon.SpringBean.aop.Logging"></bean> <aop:config> <!-- 切面class --> <aop:aspect id="log" ref="logging"> <!-- 切点 --> <aop:pointcut id="studentMethod" expression="execution(* com.seeyon.SpringBean.aop.Student.get*(..))"/> <!-- 方法执行之前触发切面class的beforeAdvice方法 --> <aop:before pointcut-ref="studentMethod" method="beforeAdvice"/> <!-- 方法执行之后触发切面class的afterAdvice方法 --> <aop:after pointcut-ref="studentMethod" method="afterAdvice"/> </aop:aspect> </aop:config>术语说明术语说明Aspect(切面)泛指交叉业务逻辑,比如日志处理、事务处理的逻辑可以理解为切面,上面xml中aop:aspect标签表示的就是一个切面。JoinPoint(连接点)连接点指切面可以织入的位置,是一个虚拟的概念,可以理解为所有满足切点扫描条件的所有的时机。Pointcut(切入点)切面具体切入的位置,上面aop:pointcut标签表示的就是一个切点,也就是满足条件被扫描到的目标方法。Advice(通知/增强)切面的一种实现,可以完成切面的功能的函数,例如日志记录,权限验证,事务控制,性能检测,错误信息检测等。Weaving(织入)指将切面的逻辑插入到目标对象中的过程。参考:https://www.jianshu.com/p/c57a5a998c6b
2020年07月16日
704 阅读
0 评论
1 点赞