Spring横切面(advice),增强(advisor),切入点(PointCut)(转)
Spring横切面(advice),增强(advisor),切入点(PointCut)的一点理解:
1.Spring管理事务有2种,其中一种是HibernateTransactionManager管理
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
这样当定义切面时可以注入会话工厂属性如下:
<!-- 配置事务处理的Bean,定义切面(advice) -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
2.对数据库的操作都属于事务的操作,而数据库默认是读已提交 read-only="true"形式
当读写操作时会调用DAO方法,而操作DAO的核心业务是Service,即 Spring,然而Spring
要对调用DAO的方法加以控制,所以就产生了切面(advice) //这个切面相当于一道防护门。
3.切面(advice)有了,Spring自己会找到应该执行哪些DAO里的方法了,(因为DAO已经注入到了Spring中;即service层引用Dao层)
所以自身的防护就变得复杂了,所以需要紧密耦合,自然增强就产生了 。如下:
<!-- 配置AOP -->
<aop:config>
<aop:pointcut id="daoMethod" expression="execution(public * com.dvp.module.*.*.*.dao.impl..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethod"/>
</aop:config>
<aop:config>
<aop:pointcut id="daoMethod2" expression="execution(public * com.dvp.base.dao.impl..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethod2"/>
</aop:config>
//OK所以一个Spring增强(advisor)=切面(advice)+切入点(PointCut)
Spring横切面(advice),增强(advisor),切入点(PointCut)(转)的更多相关文章
- Spring 通知(Advice)和顾问(Advisor)
AOP ( Aspect Oriented Programming 面向切面编程) 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译 ...
- 基于注解的Spring AOP入门、增强Advice实例
这篇文章简单通过一个例子,介绍几种增强的基本配置,以方便spring框架初学者对aop的代码结构有个清楚的了解认识.首先,spring支持aop编程,支持aspectJ的语法格式来表示切入点,切面,增 ...
- Spring的3种切入点PointCut实现
Pointcut是Join Point的集合,它是程序中需要注入Advice的位置的集合.Spring主要提供了3种切入点的实现: 1.静态切入点: 2.动态切入点: 3.自定义切入点. 静态切入点 ...
- Spring学习(20)--- Schema-based AOP(基于配置的AOP实现) -- 配置切入点pointcut
pointcut(切断点)表达式: execution(public * *(..)) execution(* set*(..)) execution(* com.xyz.service.Accoun ...
- Spring面向切面编程
在使用面向切面编程时,我们可以在一个地方定义通用的共鞥,但是可以通过声明的方式定义这个功能要以何种方式在何处应用,而无需修改受影响的类.横切关注点可以被模块化为特殊的类,这些类被称为切面.这样的优点是 ...
- Spring AOP 切面编程的方法
spring aop的使用分为两种,一种是使用注解来实现,一种是使用配置文件来实现. 先来简单的介绍一下这两种方法的实现,接下来详细的介绍各处的知识点便于查阅.目录如下: 1.基于注解实现spring ...
- Spring Aop(八)——advisor标签
转发地址:https://www.iteye.com/blog/elim-2396274 8 advisor标签 advisor标签是需要定义在aspect标签里面的,其作用与aspect类似,可以简 ...
- Spring 03 切面编程
简介 AOP(Aspect Oriented Programming),即面向切面编程 这是对面向对象思想的一种补充. 面向切面编程,就是在程序运行时,不改变程序源码的情况下,动态的增强方法的功能. ...
- 利用cglib包实现Spring中aop的<aop:advisor>功能
一:前言 还有<aop:before>/<aop:after>/<aop:around>的没有实现,不过根<aop:advisor>是差不多的,就是要额 ...
随机推荐
- 如何在Ubuntu 16.04中创建GIF动图
导读 FFmpeg 是一款开源的音.视转换器,使用 FFmpeg 我们可以非常容易地转换和录制音视频文件,而 ImageMagick 是一款用于创建.编辑和合并位图图像的一款开源软件. 大家经常在新浪 ...
- VS编程常见的编译和链接错误
常见错误1: Error 2 error LNK1120: 1 unresolved externals Error 1 error LNK2019: unresolved external symb ...
- ZH奶酪:Linux/Ubuntu 安装/卸载 软件
1.安装.deb文件 以安装Chrome为例: (1)到官方网站下载Chrome浏览器相应版本,比如google-chrome-stable_current_i386.deb: (2)Ctrl+Alt ...
- IIS 之 Web 服务器上的 ASP.NET 进程模型设置
配置 Microsoft Internet 信息服务 (IIS) Web 服务器上的 ASP.NET 进程模型设置. processModel 节只能在 Machine.config 文件中进行设置, ...
- locate 命令(转)
原文:http://www.cnblogs.com/peida/archive/2012/11/12/2765750.html locate 让使用者可以很快速的搜寻档案系统内是否有指定的档案.其方法 ...
- 触发器五(建立INSTEAD OF触发器)(学习笔记)
INSTEAD OF触发器 对于简单视图,可以直接执行INSERT,UPDATE和DELETE操作但是对于复杂视图,不允许直接执行INSERT,UPDATE和DELETE操作.为了在具有以上情况的复杂 ...
- Mapreduce实例-分组排重(group by distinct)
public class GroupComparator implements RawComparator<MyBinaryKey> { @Override public int comp ...
- kinect v1+ ubuntu 配置问题
从github上下载openni 以及 SensorKinect. install 之后 启动openni下的例子 NiViewer发生错误. Open failed: Failed to set U ...
- 【BIEE】导出数据报错
使用BIEE导出数据的时候,发现个问题,导出过程中,报错如下: 问题解决: 找到文件opmn.xml,路径为:/Middleware/instances/instance1/config/OPMN/o ...
- logging日志管理-将日志写入文件
# -*- coding: cp936 -*- # test.py #http://blog.chinaunix.net/uid-27571599-id-3492860.html #logging日志 ...