使用spring管理事务的时候,配置文件的主意事项。

来源:互联网 发布:mac照片删除后 icloud 编辑:程序博客网 时间:2024/05/17 05:04

下面是一个使用spring管理事务的配置文件例子。注意红色部分

 

<?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/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
        default-autowire="byName" default-lazy-init="true">





        <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
        <bean id="transactionManager1"
                class="org.springframework.transaction.jta.JtaTransactionManager">
        </bean>


        <aop:aspectj-autoproxy proxy-target-class="true" />


        <aop:config proxy-target-class="true">
                <aop:advisor
                        pointcut="execution(* xxx.services.impls.* .*(..))"
                        advice-ref="txAdvice" />
        </aop:config>

        <tx:advice id="txAdvice" transaction-manager="transactionManager1">
                <tx:attributes>
                        <tx:method name="get*" read-only="true"/>
                        <tx:method name="*" rollback-for="Exception"/>
                </tx:attributes>
        </tx:advice>

</beans>

 

default-autowire="byName"  如果有这个,那么

 

<bean id="transactionManager1"
                class="org.springframework.transaction.jta.JtaTransactionManager">
</bean>

 

这个bean的id,一定不能是transactionManager否则会出错,原因是  org.springframework.transaction.jta.JtaTransactionManager这个类有属性也叫 transactionManager ,所以会造成错误。

原创粉丝点击