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的配置的更多相关文章

  1. spring AOP的两种配置方式

    连接点(JoinPoint) ,就是spring允许你是通知(Advice)的地方,那可就真多了,基本每个方法的前.后(两者都有也行),或抛出异常是时都可以是连接点,spring只支持方法连接点.其他 ...

  2. (一)spring aop的两种配置方式。

    sring aop的方式有两种:(1)xml文件配置方式(2)注解的方式实现,我们可以先通过一个demo认识spring aop的实现,然后再对其进行详细的解释. 一.基于注解的springAop配置 ...

  3. Spring Aop实例之xml配置

    AOP的配置方式有2种方式:xml配置和AspectJ注解方式.今天我们就来实践一下xml配置方式. 我采用的jdk代理,所以首先将接口和实现类代码附上 package com.tgb.aop; pu ...

  4. spring AOP的两种配置

    xml配置 定义要被代理的方法的接口 public interface TestAop { public void print(String s); } 实现上述接口 public class Tes ...

  5. spring aop自动代理xml配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  6. spring aop自动代理注解配置之二

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. spring aop自动代理注解配置之一

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  8. 基于注解的Spring AOP的配置和使用

    摘要: 基于注解的Spring AOP的配置和使用 AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不 ...

  9. 基于注解的Spring AOP的配置和使用--转载

    AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...

随机推荐

  1. 计算机/linux启动过程

    开机过程指的是从打开计算机电源直到LINUX显示用户登录画面的全过程. 分析LINUX开机过程也是深入了解LINUX核心工作原理的一个很好的途径. 计算机开机过程是一个非常复杂的过程,想真正理解透彻并 ...

  2. linux 创建用户 用户组,sudo,禁止root远程ssh登录

    创建用户  useradd hanli 为新用户设置密码(在root下可以为普通用户重置密码)  passwd hanli 创建用户组  groupadd  op 将用户添加到用户组  usermod ...

  3. PyTorch 介绍 | TRANSFORMS

    数据并不总是满足机器学习算法所需的格式.我们使用transform对数据进行一些操作,使得其能适用于训练. 所有的TorchVision数据集都有两个参数,用以接受包含transform逻辑的可调用项 ...

  4. 用socket写一个简单的服务器

    import socketsk=socket.socket()sk.bind(("127.0.0.1",7001))sk.listen()def login(url): with ...

  5. Java当中“+=”和“=+”的区别

    "+="会自动类型强制转换! 隐含了一个强制类型转换! 一 string a1 = "9"; int a2 = 10; a1+=a2; a1=a1+a2; 不会 ...

  6. TensorFlow 卷积神经网络实用指南 | iBooker·ApacheCN

    原文:Hands-On Convolutional Neural Networks with TensorFlow 协议:CC BY-NC-SA 4.0 自豪地采用谷歌翻译 不要担心自己的形象,只关心 ...

  7. Java 数组存储机制

    数组是一种引用类型. 数组用来存储类型相同的一组数据,一旦初始化完成,其所占的空间也确定下来了,即使清除某个元素,其所占用的空间仍然存在,即,数组的长度不能被改变,且数组只有在分配空间后才能使用. 数 ...

  8. 设置程序启动时加载的storyboard

    这个设置表明:程序启动时会加载Main.storyboard

  9. vi/vim 设置.vimrc(/etc/vim | $HOME)

    转载请注明来源:https://www.cnblogs.com/hookjc/ "====================================================== ...

  10. High ASCII字符从bat文件到dos控制台的转化问题

    背景是这样的,由于项目需要,需要用silent install的方式安装一些程序,而安装参数中有一些High ASCII字符,如ùé.通过代码,使用默认编码(ANSI,说明下,我用的是法语的系统)创建 ...