spring of using transactions (b)

Connect one: https: //www.cnblogs.com/xiximayou/p/12167894.html

To address these issues using the transaction.

Configure the transaction manager in the applicationContext.xml:

    <!-- 配置事务管理器 -->
    <bean id="transactionManager" 
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

Enable transaction Note:

    <! - Enable transaction comment -> 
    < tx: Annotation-Driven Transaction-Manager = "transactionManager" />

Then add the transaction comment on the purchase method:

    @Transactional
    @Override
    public void purchase(String username, String isbn)

At this point, we run testBookShopService method, found that when the balance is insufficient, inventory and will not be reduced.

Guess you like

Origin www.cnblogs.com/xiximayou/p/12168449.html