spring中的事务管理

首先需要在bean头引入

 xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/spring-tx.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd"

jdbc事务

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

配置事务的通知,例子如下:

<tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add" propagation="REQUIRED"/>
            <tx:method name="delete" propagation="REQUIRED"/>
            <tx:method name="update" propagation="REQUIRED"/>
            <tx:method name="search" propagation="REQUIRED"/>
            <tx:method name="get" read-only="true"/>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>

配置aop头文件

<aop:config>
    <aop:pointcut id="txPointcut" expression="execution(* com.zte.pojo.*.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>

 

posted @ 2022-07-28 21:00  mountain_city_boy  阅读(27)  评论(0)    收藏  举报