spring事物管理 面向切面,声明式事物

spring事物管理 面向切面,声明式事物
1.导入jar包
2.配置spring配置文件(applicationContext)
修改命名空间(头部文件)文件在spring的帮助文档中获得
3.整合hibernate(spring 提供了声明式事物不用在程序中写事物代码,而是利用面向切面技术在配置中声明定义的方法是事物性的,避免代码重复)
使用事物管理机制:
1.配置事务管理器。
<bean id="自己起"
class="org.springframework.orm.hibernate3.hibernateTransactionManager">
<property name="sessionFactory" ref="引用我们自己创建的sessionfactory"/>
</bean>
2.配置事物通知;
配置规则,管理事物的时候就会按照配置的规则来进行管理
<tx:advice id="txAdvice"transaction-manager="txManager">
<tx:attributes>事物属性
<tx: methodname="*" 表示适用于所有方法
propagation="REQUIRED"
rollback-for="java.lang.Exception"/>发生异常时 回滚 可以制定特定异常
</tx:attribtes>
</tx:advice>
3配置事物切面(规定事物运用的位置)
<aop:config>
<aop:advisor
advice-ref="txAdvice"
pointcut="execution(*" 引用位置")"
</aop:config>

posted on 2015-09-18 11:15  就是爱学习呀  阅读(332)  评论(0)    收藏  举报

导航