归纳点:
要想事务配置成功:
1, 要在applicationContext-tran.xml配置文件中 添加事务的注解驱动,必须要有.
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
2. 在业务层业务实现类必须要加@Transaction注解
3. 在业务层业务实现类catch块中必须要throw一个异常,以便触发回滚(这是触发回滚的一个条件)
4. spring-MVC.xml中要扫具体包只扫到Controller, 因为spring-MVC.xml是输入dispatcherServlet的,而applicationContext.xml,applicationContext-tran.xml是输入contextLoaderListener的, 因此spring-MVC.xml的加载要晚于它俩,会造成本已增加过的方法被覆盖