配置spring的事务管理
2009-11-16 16:38
453 查看
网上看到过很多关于spring事务管理的东西,但是原创的并不多,如果你的运气好能看到那些原创的文章恭喜你,因为我看到的不多,但一些原创的文
章里面枝叶太多,因为那些高手直接把自己的代码拷过来,所以说无疑给一些初学者或一些目前知识面有限的读者带来了很大的困难,本人就去掉枝叶,只给主干
1,配置sessionFactory
<bean id="sessionFactory" class="org.springframwork.orm.hibernate3.LocalSessionFactory">
<property name="configLocation">
<ref bean="classpath:hibernate.cfg.xml" />
</property>
</bean>
2,配置事务控制器
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateSessionFactoryBean">
<property name="sessionFactory" ref="sessionFactory">
</bean>
3,配置事务的传播性
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:mehtod name="*" read-only="true">
</tx:attributes>
</tx:advice>
4,配置那些类的那些方法需要事务
<aop:config>
<aop:pointcut id="allMethod" expression="execution(* com.simpl.*.*(..))" />
<aop:advisor pointcut-ref="allMethod" advice-ref="txAdvice" />
</aop:config>
解释一下<execution>中的内容的意思:就是com.simp包下的所有类的所有方法,*正则表达式中的通配符,其中在包前面有一个*代表返回类型为任意类型。其中execution中的表达式可以用逻辑“或”连接多个表达式的
章里面枝叶太多,因为那些高手直接把自己的代码拷过来,所以说无疑给一些初学者或一些目前知识面有限的读者带来了很大的困难,本人就去掉枝叶,只给主干
1,配置sessionFactory
<bean id="sessionFactory" class="org.springframwork.orm.hibernate3.LocalSessionFactory">
<property name="configLocation">
<ref bean="classpath:hibernate.cfg.xml" />
</property>
</bean>
2,配置事务控制器
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateSessionFactoryBean">
<property name="sessionFactory" ref="sessionFactory">
</bean>
3,配置事务的传播性
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:mehtod name="*" read-only="true">
</tx:attributes>
</tx:advice>
4,配置那些类的那些方法需要事务
<aop:config>
<aop:pointcut id="allMethod" expression="execution(* com.simpl.*.*(..))" />
<aop:advisor pointcut-ref="allMethod" advice-ref="txAdvice" />
</aop:config>
解释一下<execution>中的内容的意思:就是com.simp包下的所有类的所有方法,*正则表达式中的通配符,其中在包前面有一个*代表返回类型为任意类型。其中execution中的表达式可以用逻辑“或”连接多个表达式的
相关文章推荐
- Spring入门之事务管理【一】XML配置文件方式
- spring使用TransactionProxy配置声明式的事务管理
- spring 事务管理配置
- Spring注解配置事务管理——问题
- Spring事务管理中@Transactional的参数配置
- spring事物配置,声明式事务管理和基于@Transactional注解的使用(1)
- Spring管理的事务:如何配置回滚及try catch情况下的回滚
- spring 管理的事务。个人理解(SSH项目注解配置)
- Spring的事务管理,applicationContext.xml中的配置
- Spring配置事务管理和简化事务配置
- spring.net tx:advice 和 aop:config 配置事务 匹配名字的方法管理事务
- Spring管理 hibernate 事务配置的五种方式
- spring事物配置,声明式事务管理和基于@Transactional注解的使用
- spring事物配置,声明式事务管理和基于@Transactional注解的使用
- spring事物配置,声明式事务管理和基于@Transactional注解的使用
- spring事物配置,声明式事务管理和基于@Transactional注解的使用
- Spring 声明式事务管理 Annotation配置 xml文件
- spring+springMVC中使用@Transcational方式管理事务的配置方法
- 关于Spring 事务管理传播属性的配置及作用-嵌套事务
- spring的事务管理器的配置