Spring事务管理
来源:互联网 发布:java如何让窗口置顶 编辑:程序博客网 时间:2024/06/06 20:50
Spring事务配置流程
首先得先把这个图理解清楚,这个图有助于理解在配置中的一些东西。 在这里主要说的是用hibernate声明式的事务管理的事务配置,具体的详解请看: [事务配置详情](http://blog.csdn.net/trigl/article/details/50968079)。
事务配置基本流程
1:声明使用的事务管理平台(PlateformTransactionManager)。 2:定义事务的一些策略(TransactionDefinition)。 3:规定哪些类使用事务。 4:使用注解的方式使用(@Transactional)。
详细配置信息
<!-- 事务管理 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!--配置一些事务的行为 比如 事务的传播,事务是否只读,事务超时,隔离规则,回滚规则等(也可以叫做事务的定义) --> <tx:advice id="advice" transaction-manager="transactionManager"> <tx:attributes> <!-- 定义事务的传播行为:required:以save开头的方法必须运行在事务中,如果事务不存在,将会开启一个新的事物,supports:如果有事务就运行在事务当中 --> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="*" propagation="SUPPORTS" /> </tx:attributes> </tx:advice> <!-- 配置哪些包的类要切入事务 --> <aop:config> <aop:pointcut id="pointcut" expression="execution(* cn.it.shop.service.impl.*.*(..))" /> <!-- 连接了上面的advice和上面的pointcut --> <aop:advisor advice-ref="advice" pointcut-ref="pointcut" /> <!-- 出现一个很奇怪的问题,aop:pointcut要写在aop:advisor上面,否则会报错 --> </aop:config>
注意
1:声明式的事务管理,只能作用到方法,或类上,不能作用到具体的代码块上。 2:想要使用注解得在spring的配置文件中加上: <context:annotation-config /> <context:component-scan base-package="cn.it.shop.." /> 3:对于注释的理解就是把这些注释了得组件 加载到spring的管理中去,然后spring通过注释的关键字去找在spring中关于这个组件的相关配置。 4:对定义的一些事务属性或策略说明: <!-- isolation: 隔离级别,timeout:事务超出时间,no-rollback-for:事务发生异常时回滚的自定义的异常类 --> <tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED" timeout="1" no-rollback-for="自定义的异常类"/>
阅读全文
0 0
- 事务管理之Spring事务管理
- Spring事务管理
- spring事务管理
- Spring事务管理
- Spring事务管理
- Spring事务管理
- Spring事务管理
- Spring事务管理
- Spring 事务管理
- Spring事务管理
- spring 事务管理
- spring 事务管理
- spring 事务管理
- spring事务管理
- Spring 事务管理
- Spring事务管理
- spring事务管理
- spring 事务管理
- 多线程的四种状态及同步机制的应用(火车票线程同步)
- UVa1629 Cake Slicing
- poj 2985 The k-th Largest Group (Treap+并查集)
- python3与2的区别
- Hbase shell 命令
- Spring事务管理
- linux系统服务状态
- 三(6)、JSP九大内置对象——application
- xml之JDOM解析(含乱码处理)
- ubuntu修改为阿里源
- 黑盒测试与白盒测试
- firefox浏览器一分钟去广告--去广告插件安装教程(adblock plus)
- 集合框架(数据结构之链表二)--------(上一篇补充)
- 深入学习Java之HashMap