Spring AOP之3w的配置
1、3w是什么?
■ what、where、when 或者 what、when、where
2、what、where、when【通用】
(1)what:增强器-bean【配置一个bean对象】
(2)where:被增强的连接点-aop:pointcut【配置被增强的方法的属性-expression】
(3)when: 被增强的时机-aop:before/after-returning/after-throwing/after/around【前置、后置、异常、最终、环绕】
★ 3w 之间的关联:
■ where 和 when 同处在 元素aop:aspect 内部:
【where、when】整体-关联 what 是通过 元素aop:aspect 的属性 ref 关联是bean的增强器(what)
■ 内部的 when 和 where 之间:when 通过 pointcut-ref 关联到 where
<!-- AOP 配置:what、where、when -->
<!-- 1、what:做什么增强 -->
<bean id="transactionManager" class="com.shan.tx.TransactionManager"/>
<aop:config>
<!-- 配置AOP切面 -->
<aop:aspect ref="transactionManager"> <!-- ✿ 关联what -->
<!-- 2、where:在哪些包中的哪些类中的哪些方法上做增强 -->
<aop:pointcut id="txPoint" expression="execution(* com.shan.service..*Service*.*(..))"/>
<!-- 3、when:在方法执行的什么时机做增强 -->
<aop:before method="open" pointcut-ref="txPoint"/> <!-- ✿ 关联where -->
</aop:aspect>
</aop:config>
3、what、when、where【事务管理器特有】
(1)what:增强器-bean【配置一个bean对象】
(2)when: 被增强的时机(事务环绕增强特有)-tx:advice
(3)where:被增强的连接点-aop:pointcut【配置被增强的方法的属性-expression】
★ 3w 之间的关联:
■ when 和 what 之间:when 通过 (事务环绕增强特有)-tx:advice的属性 transaction-manager 关联是bean的增强器(what)
■ where 和 when 同处在 元素aop:config 内部:
通过元素aop:config的子元素aop:pointcut关联到where,然后又通过元素aop:config的子元素aop:advisor关联到when
<!-- 1、what:配置jdbc事务管理器 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 2:when:配置事务管理器增强(环绕增强) --><!-- ✿ 关联what -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="trans"/>
</tx:attributes>
</tx:advice>
<!-- 3、where:配置切面 -->
<aop:config>
<aop:pointcut id="txPc" expression="execution(* com.shan.service.*Service.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPc"/><!-- ✿ 关联when -->
</aop:config>
Spring AOP之3w的配置的更多相关文章
- spring AOP的两种配置方式
连接点(JoinPoint) ,就是spring允许你是通知(Advice)的地方,那可就真多了,基本每个方法的前.后(两者都有也行),或抛出异常是时都可以是连接点,spring只支持方法连接点.其他 ...
- (一)spring aop的两种配置方式。
sring aop的方式有两种:(1)xml文件配置方式(2)注解的方式实现,我们可以先通过一个demo认识spring aop的实现,然后再对其进行详细的解释. 一.基于注解的springAop配置 ...
- Spring Aop实例之xml配置
AOP的配置方式有2种方式:xml配置和AspectJ注解方式.今天我们就来实践一下xml配置方式. 我采用的jdk代理,所以首先将接口和实现类代码附上 package com.tgb.aop; pu ...
- spring AOP的两种配置
xml配置 定义要被代理的方法的接口 public interface TestAop { public void print(String s); } 实现上述接口 public class Tes ...
- spring aop自动代理xml配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- spring aop自动代理注解配置之二
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- spring aop自动代理注解配置之一
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 基于注解的Spring AOP的配置和使用
摘要: 基于注解的Spring AOP的配置和使用 AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不 ...
- 基于注解的Spring AOP的配置和使用--转载
AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
随机推荐
- 有关softmax函数代码实现的思考
有关softmax函数代码实现的思考 softmax函数 def softmax2(x): if x.ndim == 2: x = x.T x = x - np.max(x, axis=0) y = ...
- JavaScripts之迪卡算法求积(n*n)适用于SKU信息计算等场景
迪卡算法求积(n * n) 使用 array.reduce 的方式实现 笛卡尔积算法 const arr = [ ['黑色', '白色', '蓝色'], ['1.2KG', '2.0KG', '3.0 ...
- Python打印JSON中中文的解决办法
code #!/usr/bin/python # encoding=utf-8 import json data = [{"a": "中文"}] print j ...
- plsql 函数的定义 包规范和包主体。
/* 一.函数? 1.函数定义 函数的内容 根据实际需要来定义 2.使用的方式 */ -- 定义函数 根据部门编号查询出部门的总人数 create or replace function fn( de ...
- 计算机电子书 2018 BiliDrive 备份
下载方式 根据你的操作系统下载不同的 BiliDrive 二进制. 执行: bilidrive download <link> 链接 文档 链接 Webpack 中文指南.epub (40 ...
- 「CTSC 2011」幸福路径
[「CTSC 2011」幸福路径 蚂蚁是可以无限走下去的,但是题目对于精度是有限定的,只要满足精度就行了. \({(1-1e-6)}^{2^{25}}=2.6e-15\) 考虑使用倍增的思想. 定义\ ...
- 看一遍就懂:MVCC原理详解
MVCC实现原理也是一道非常高频的面试题,自己在整理这篇文章的时候,感觉到网上的资料在讲这块知识点上写的五花八门,好像大家的理解并没有一致. 这里将自己所理解的做一个总结,个人会觉得这是一篇含金量挺高 ...
- Maven仓库的目录结构
_remote.repositories文件 本地库中的包都有一个_remote.repositories文件,示例: #NOTE: This is an Aether internal implem ...
- bom-scroll
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- ObjectInputStream java.io.StreamCorruptedException: invalid type code: AC问题解决
感谢原文作者:攻城狮_无名 原文链接:https://blog.csdn.net/mingyang_2016/article/details/75208117 问题描述: 每次向一个文件中序列化对象时 ...