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. 【程序5】输入三个整数x,y,z,请把这三个数由小到大输出

    我自己写的: x = int(input('x:')) y = int(input('y:')) z = int(input('z:')) L = [x,y,z] print(sorted(L)) 官 ...

  2. git 初始化本地项目并推送到远程

    有一个新项目,开发了一些代码之后想推送到远程,具体的操作方式和命令如下: (使用 git bash) 1.切到项目目录中,例如 E:\git\smart-open 2.初始化git仓库并在本地提交 / ...

  3. Entity Framework 在OrderBy排序中使用字符串

    public static class LinqExtensions { private static PropertyInfo GetPropertyInfo(Type objType, strin ...

  4. response.getWriter().write()和 response.getWriter().print()的区别 以及 PrintWriter对象 和 out对象 的区别

    感谢原文作者:krismile__qh 原文链接:https://blog.csdn.net/krismile__qh/article/details/89926001 一.response.getW ...

  5. JavaWeb编码浅解

    感谢原文作者:少年无形 原文链接:https://blog.csdn.net/dl18215164175/article/details/72512131?depth_1-utm_source=dis ...

  6. Mysql Json函数之搜索 (三)

    本节中的函数对JSON值执行搜索操作,以从其中提取数据,报告数据是否在其中的某个位置或报告其中的数据的路径. JSON_CONTAINS(target, candidate[, path]) 通过返回 ...

  7. ORM要用到的数组转对象和对象转数组函数

    <?php function array2object($array) { if (is_array($array)) { $obj = new StdClass(); foreach ($ar ...

  8. iOS中处理时间的类

      登录|注册     sakulafly的专栏       目录视图 摘要视图 订阅 Markdown博文大赛清新开启    天天爱答题 一大波C币袭来    中国云计算大会演讲议题公布     大 ...

  9. 如何快速为团队打造自己的组件库(上)—— Element 源码架构

    文章已收录到 github,欢迎 Watch 和 Star. 简介 详细讲解了 ElementUI 的源码架构,为下一步基于 ElementUI 打造团队自己的组件库打好坚实的基础. 如何快速为团队打 ...

  10. Charles抓包工具介绍

    1.Charles是什么? Charles是一款基于http协议的代理服务器,通过称为电脑或者浏览器的代理,然后截取请求和请求结果达到分析抓包的目的. 2.Charles有哪些用途? (1)能够分析前 ...