Spring声明式事务XML方式以及注解式事务

对于转账环境请看前篇https://mp.csdn.net/postedit/87891375

新的xml:

<bean id="accountService" class="tx.AccountServiceImplement">
        <property name="accountDao" ref="accountDao"/>
    </bean>
    <!--Dao-->
    <bean id="accountDao" class="tx.AccountDaoImplement">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
    <!--配置c3p0连接池-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="driverClass"/>
        <property name="jdbcUrl" value="${jdbcUrl}"/>
        <property name="user" value="${user}"/>
        <property name="password" value="${password}"/>
    </bean>

    <!--配置平台事务管理=======-->
    <bean id="transactionMsnger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <tx:advice id="txAdvice" transaction-manager="transactionMsnger">
        <tx:attributes>
            <tx:method name="transfer" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>

    <aop:config>
        <aop:pointcut expression="execution(* tx.AccountServiceImplement.*(..))" id="pointcut" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>
    </aop:config>

注解式:

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

    <tx:annotation-driven transaction-manager="transactionMsnger"></tx:annotation-driven>
服务层
@Transactional
public class AccountServiceImplement implements AccountService {

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值