spring2.5 hibernate 配置最少的事务处理(声明切面)
来源:互联网 发布:linux 查询文件夹大小 编辑:程序博客网 时间:2024/05/16 12:26
需要事务处理的方法:
该方法所在类不需要实现任何接口!!
public class aservers{
@Autowired
private DeptDAO deptopt;//spring 来完成deptopt的初始化 不需要写getter setter
public void insertDemoData() throws Exception{//一定不要自己catch抛出异常,否则不能回滚
Dept dept1=new Dept();
dept1.setName("事业部");
deptopt.save(dept1);
int i=1/0; //异常
}
}
spring 配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<!-- 定义切面 -->
<aop:config>
<aop:pointcut id="serviceOperation"
<!-- 模糊匹配需要拦截的包 -->
expression="execution(* com.casw.ssh.dept.actions.*.*(..))"/>
<aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/>
</aop:config>
<!-- 定义需要管理的方法 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager" >
<tx:attributes>
<!-- 模糊匹配需要拦截的方法 -->
<tx:method name="find*" read-only="true" />
<tx:method name="insert*" />
</tx:attributes>
</tx:advice>
<!-- 定义事务管理器,使用适用于Hibernte的事务管理器-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- HibernateTransactionManager bean需要依赖注入一个SessionFactory bean的引用-->
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!--其他配置略-->
OK 配置完毕, 出异常的话就会回滚,注释掉 int i=1/0, 就会更新数据库。
其实这样配置的最大好处就是aservers不需要 实现什么接口了,
- spring2.5 hibernate 配置最少的事务处理(声明切面)
- Spring2.5 + Hibernate 的annotation配置
- spring2.5+hibernate基于xml配置的实例
- Spring+Hibernate的事物切面配置
- spring2.0 配置AOP(切面)
- spring1.x与spring2声明式事务管理的配置
- spring1.x spring2的声明式事务配置
- spring 配置hibernate事务处理
- Spring2.5+OpenJPA的配置
- Spring2.5的基本配置
- Spring的事务处理之声明式事务处理
- spring声明式事务处理(hibernate)
- 配置Spring2.0声明式事务
- (11) 基于XML配置方式声明切面
- Spring 的声明式事务处理
- Spring的声明式事务处理
- struts2+hibernate+spring2.5用properties集成整合配置方法
- Hibernate的事务处理机制
- powerbuilder 修改自定义函数声明
- flex 组件 和 样式 一览表
- 流光溢彩
- PaperVision 3D引擎demo汇总 (好老啊)
- 上班族流行“黑话”大全
- spring2.5 hibernate 配置最少的事务处理(声明切面)
- 关于uiimage的比例缩放、及图片截取
- 收藏几个flex 创意网站
- Flash & Flex组件优化的杀手锏callLater
- 外界与Flex Application的交互处理(之嵌入html)
- Flex程序与html通信方法大全
- 12个Flex常用功能代码
- flex 自定义 屏蔽 右键菜单
- TSO/E PROFILE配置