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的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
随机推荐
- linux信号 SIGINT SIGTERM SIGKILL
三者都是结束/终止进程运行. 1.SIGINT SIGTERM区别 前者与字符ctrl+c关联,后者没有任何控制字符关联. 前者只能结束前台进程,后者则不是. 2.SIGTERM SIGKILL的区别 ...
- nginx多ip多端口多域名方式
目录 一:Nginx虚拟主机 1.基于ip的方式 2.基于多端口的方式 3.基于多域名的方式 一:Nginx虚拟主机 基于多IP的方式 基于多端口的方式 基于多域名的方式 1.基于ip的方式 [roo ...
- kubernetes之添加删除node
添加node 1.master生成token [root@node-01 ~]# kubeadm token create --print-join-command kubeadm join 172. ...
- python15day
昨日回顾 装饰器:完美的呈现了开放封闭原则.本质:闭包. def wrapper(f): def inner(*args,**kwargs): '''在执行被装饰函数之前,想写什么代码写什么代码''' ...
- Linux 配置mysql 免安装版。
二.Linux配置 mysql ? 1.linux配置mysql(要求全部使用免安装版) 5.1.从官网下载mysql5.tar.gz 5.2.使用xftp把mysql的压缩包上传到服务器上 5.3. ...
- shiro 快速入门详解。
package com.aaa.lee.shiro; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authc.*; i ...
- 双系统之删除Linux以及grub的引导
问题阐述:最近玩双系统,把linux系统搞崩了,回到windos备份Linux系统的数据就把Linux的盘格式化了,然后再每当进入系统都会出现grub的命令格的窗口,输入任何命令都报错? 解决方法: ...
- redis中scan和keys的区别
scan和keys的区别 redis的keys命令,通来在用来删除相关的key时使用,但这个命令有一个弊端,在redis拥有数百万及以上的keys的时候,会执行的比较慢,更为致命的是,这个命令会阻塞r ...
- NSArray文件读写
1.NSArray数据写入到文件中 NSArray *arr = @[@"lnj", @"lmj", @"jjj", @"xcq& ...
- Java.lang.Integer类中toString(int i, int radix)的具体实现
Java.lang.Integer.toString(int i,int radix)方法可以实现将一个int类型的10进制的数据转换为指定进制的数据. api文档中介绍: 返回第二个参数指定的基数中 ...