使用spring一般配置事务怎么配置

J2EE 码拜 9年前 (2015-04-13) 1056次浏览 0个评论
 

  <bean id=”transactionManager”
        class=”org.springframework.orm.hibernate3.HibernateTransactionManager”>
        <property name=”sessionFactory” ref=”sessionFactory” />
    </bean>

    <tx:advice id=”txAdvice” transaction-manager=”transactionManager”>
        <tx:attributes>
            <tx:method name=”*” propagation=”REQUIRED” />
        </tx:attributes>
    </tx:advice>
    
    <aop:config>
        <aop:pointcut id=”interceptorPointCuts”
            expression=”execution(* com.asp.service.*Service.*(..))” />
        <aop:advisor advice-ref=”txAdvice”
            pointcut-ref=”interceptorPointCuts” />        
    </aop:config>      
直接这样就好了吗  大家一般在项目中都这么配置事务的吗

使用spring一般配置事务怎么配置
10分
现在都用注解了吧
使用spring一般配置事务怎么配置
这个是事务 ???
使用spring一般配置事务怎么配置
引用 2 楼 Yweige2010 的回复:

这个是事务 ???

这个不是事务  那这是什么呢

使用spring一般配置事务怎么配置
10分
你这个配置的范围也太大了 基本上service 中所有的方法都一样了。一般我们查询的时候没必要 我项目中是这样配置的
<tx:advice id=”txAdvice” transaction-manager=”txManager”>
<tx:attributes>
<!– 需要由交给spring的aop来进行代理的方法的集合,如果应用有自己的方法需有由spring来进行事务控制必须添加方法 –>

<!– 读取数据方法,一般采用只读事务 –>
<tx:method name=”get*” read-only=”true” />
<tx:method name=”load*” read-only=”true” />
<tx:method name=”select*” read-only=”true” />
<tx:method name=”query*” read-only=”true” />
<tx:method name=”criteria*” read-only=”true” />
<tx:method name=”find*” read-only=”true” />
<tx:method name=”count*” read-only=”true” />

<!–其他方法,如save,update,insert,monitor等对数据库进行写入操作的方法,当产生ServiceException进行回滚 –>
<tx:method name=”submit*” read-only=”false” rollback-for=”ServiceException” />
<tx:method name=”enable*” read-only=”false” rollback-for=”ServiceException” />
<tx:method name=”disable*” read-only=”false” rollback-for=”ServiceException” />
<tx:method name=”insert*” read-only=”false” rollback-for=”ServiceException” />
<tx:method name=”update*” read-only=”false” rollback-for=”ServiceException” />
<tx:method name=”lock*” read-only=”false” rollback-for=”ServiceException”
propagation=”REQUIRED” />

<aop:config>
<aop:pointcut id=”serviceOperation”
expression=”execution(* com.jc.qrmp..*Service.*(..))” />
<aop:pointcut id=”approveInterceptor”
expression=”execution(* com.jc.qrmp.aop.ApproveInterceptor.*(..))” />
<aop:advisor pointcut-ref=”serviceOperation” advice-ref=”txAdvice” />
<aop:advisor pointcut-ref=”approveInterceptor” advice-ref=”txAdvice” />
</aop:config>
只是代码片断 ,供你参考


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明使用spring一般配置事务怎么配置
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!