2011-08-23 93 views

回答

1

你想看看@Transactional註釋docs 就最佳實踐而言,它是數據庫事務和spring的混合體。看看你需要回滾你的數據,你需要JTA等

例類

@Transactional 
public class DefaultFooService implements FooService { 

    Foo getFoo(String fooName); 
} 

示例XML

<!-- this is the service object that we want to make transactional --> 
<bean id="fooService" class="x.y.service.DefaultFooService"/> 
<!-- enable the configuration of transactional behavior based on annotations -->   <tx:annotation-driven transaction-manager="txManager"/> 

<!-- a PlatformTransactionManager is still required --> 
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
<!-- (this dependency is defined somewhere else) --> 
    <property name="dataSource" ref="dataSource"/> 
</bean>