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的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
随机推荐
- ElasticSearch+Kibana+Packetbeat
一.介绍 Packetbeat 是一个实时网络数据包分析工具,通过嗅探应用服务器之间的网络通讯,来解码应用层协议类型如HTTP.MySQL.redis等等,关联请求与响应,并记录每个事务有意义的字段. ...
- 『无为则无心』Python基础 — 43、文件备份的实现
目录 1.需求 2.步骤 3.代码实现 (1)接收用户输入目标文件名 (2)规划备份文件名 (3)备份文件写入数据 (4)思考 (5)完整编码 4.再来一个小练习 1.需求 用户输入当前目录下任意文件 ...
- 随机UA
from fake_useragent import UserAgent ua = UserAgent().random headers={ 'User-Agent':ua } print(heade ...
- 【源码】Redis命令处理过程
本文基于社区版Redis 4.0.8 1.命令解析 Redis服务器接收到的命令请求首先存储在客户端对象的querybuf输入缓冲区,然后解析命令请求的各个参数,并存储在客户端对象的argv和ar ...
- 微信、QQ添加Universal Link
官方说明 1. Universal Links是什么 Universal Links(通用链接),是苹果在iOS9之后,提供的一种"可通过传统HTTP链接来跳转APP"的能力. 该 ...
- 设置鼠标光标与页面favicon
鼠标光标 body{cursor: url('http://image.XXXX.com/ii.png'),default;} 2. favicon <link rel="shortc ...
- Linux命令date日期时间和Unix时间戳互转
A.将日期转换为Unix时间戳将当前时间以Unix时间戳表示: date +%s 输出如下: 1361542433 转换指定日期为Unix时间戳: date -d '2013-2-22 22:14' ...
- linux计划任务之cron
目录 cron计划任务之用户级 cron计划任务之系统级 cron计划任务之用户级 1.安装crond centos7 执行命令: # yum install -y crontabs /bin/sys ...
- indexOf() 和 lastIndexOf()
一,定义和用法 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置. lastIndexOf() 方法可返回一个指定的字符串值最后出现的位置,在一个字符串中的指定位置从后向前搜索 ...
- 如何添加自己的code snippet
好了我们开始说吧 1.先建一个后缀名为.sublime-snippet的文件