Spring和mybatis结合后,由Spring接管mybtis事物。此配置适应于扩展性事物。具体配置如下
第一步:applicationContext.xml相关配置如下:
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 开启注解配置 -->
<context:annotation-config />
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
第二步:在service中采用注解的形式声明事物
@Transactional
public class LoginServicesImpl implements ILoginServices