spring 管理事物!求解!! 求!用spring怎么更好的管理事物。偶遇这道题目, 把我给难住了 ,求各位神人帮忙解答一下!!谢谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Spring有两种事务管理方式,编程式事务管理和声明式事务管理.编程式事务管理可以实现细粒度的事务控制.声明式事务管理只需要在Spring配置文件中做一些配置,即可将操作纳入到事务管理中,解除了和代码的耦合,这是对应用代码影响最小的选择.这也体现了Spring的AOP 希望楼主结贴给分呵呵!把这写代码考入到你的applicationContext.xml文件中注意把你上面的版本用这段代码替换掉这是spring AOP首先:<?xml version="1.0" encoding="UTF-8"?><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.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">========================================================================其次:<!-- 声明式事务帮助业务逻辑实现数据库CUD --> <bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="mySessionFactory"/> </bean> <tx:advice id="txAdvice" transaction-manager="myTxManager"> <tx:attributes> <tx:method name="create*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="delete*" propagation="REQUIRED"/> <tx:method name="read*" propagation="SUPPORTS" read-only="true"/> </tx:attributes> </tx:advice> <!-- 将通知给这个切点 advice-ref表示事务通知,pointcut-ref表示谁需要这个事务--> <aop:config> <!-- 表示过滤aa.cc.*.*(..)包下面的所有方法--> <aop:pointcut id="bizServiceMethods" expression="execution(* aa.cc.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="bizServiceMethods"/> </aop:config> 楼主问的范围有些大~我们指的事务 主要是针对数据库操作的一般将service层的操作作为一个整体的事务当然spring实现事务的原理 离不开AOP的拦截 j2ee发布成webservice(axis2) 一个初学者的SPRING问题,高手帮忙看看! 小女子不才,接触J2EE/EJB不久碰到的问题!跪求帮助!!! 还是乱码那点事。。。 算法问题 hibernate连mysql,长时间不动后,报错? spring处理blob字段问题 [200分]在jsp中如何用hibernate实现分页,怎样在jbuilderx配置开发,最好给个例子,我是新手! 有什么办法可以用jar包编译成dll吗? java调用存储过程 关于实体中的集合属性 myeclipse调试servlet和jsp调试时候出现如图
把这写代码考入到你的applicationContext.xml文件中
注意把你上面的版本用这段代码替换掉这是spring AOP首先:
<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">========================================================================
其次:<!-- 声明式事务帮助业务逻辑实现数据库CUD -->
<bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="myTxManager">
<tx:attributes>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="read*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 将通知给这个切点 advice-ref表示事务通知,pointcut-ref表示谁需要这个事务-->
<aop:config>
<!-- 表示过滤aa.cc.*.*(..)包下面的所有方法-->
<aop:pointcut id="bizServiceMethods"
expression="execution(* aa.cc.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="bizServiceMethods"/>
</aop:config>
一般将service层的操作作为一个整体的事务
当然spring实现事务的原理 离不开AOP的拦截