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的缩写,意思是面向切面编程.可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术. ...
随机推荐
- IDEA设置Maven
1,在idea中设置maven,让idea和maven结合使用 idea中内置了maven,一般不使用内置,因为用内置修改maven的设置不方便 使用自己安装的maven,需要覆盖idea中默认的设置 ...
- IEEE754浮点数表示法
IEEE二进制浮点数算术标准(ANSI/IEEE Std 754-1985)是一套规定如何用二进制表示浮点数的标准.就像"补码规则"建立了二进制位和正负数的一一对应关系一样,IEE ...
- nginx模块lnmp架构
目录 一:关于lnmp架构 二:目录索引模块 1.目录索引模块内容 1.开启目录索引(创建模块文件) 2.测试 3.重启nginx 4.配置域名解析DNS 5.网址测试 二:目录索引(格式化文件大小) ...
- linux 常用命令。
/* Linux常用命令? 1 查看 ls 展示当前目录下的可见文件 ls -a 展示当前目录下所有的文件(包括隐藏的文件) ls -l(ll) ...
- 【Python爬虫】爬虫利器 requests 库小结
requests库 Requests 是一个 Python 的 HTTP 客户端库. 支持许多 HTTP 特性,可以非常方便地进行网页请求.网页分析和处理网页资源,拥有许多强大的功能. 本文主要介绍 ...
- 使用 TensorFlow 构建机器学习项目中文版·翻译完成
原文:Building Machine Learning Projects with TensorFlow 协议:CC BY-NC-SA 4.0 不要担心自己的形象,只关心如何实现目标.--<原 ...
- JS 将Table内容导出到Excel(样式设计)
转载请注明来源:https://www.cnblogs.com/hookjc/ function saveAsExcel(tableID){ var tb = new TableToExcel(tab ...
- VC 为程序创建唯一标识
转载请注明来源:https://www.cnblogs.com/hookjc/ 应用: 一台机器上只许运行一个客户端 同一个账号只允许登陆一个客户端 BOOl m_IsRun=false; HANDL ...
- 模仿UIApplication单例
要求:程序一启动就创建创建对象.创建的对象只能通过share的⽅方式获取对象.不能够进行alloc 操作,当执⾏行alloc时, 程序发生崩溃 1.程序一启动的时候就创建对象.当类被加载到内存的时候就 ...
- Linux用户配置文件、口令配置文件、组配置文件
1.用户配置文件:保存用户信息 /etc/passwd 2.口令配置文件 /etc/shadow 每一行解释:登录名:加密口令:最后一次修改时间:最小时间间隔:最大时间间隔:警告时间:不活动时间:失效 ...