当我在服务方法中抛出异常时,我期望服务上的事务注释会回滚保存操作,但这并不起作用。
这是我的服务:
@Service
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public class OrderServiceImp implements OrderService {
@Autowired
private OrderRepository orderRepository;
@Override
public void doSomeStaff(Long orderId) {
Order order = orderRepository.findOne(orderId);
orderRepository.save(order);
throw new NullPointerException("Test transaction exeption");
}
}
在 data.xml 文件中,我有以下配置:
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<jpa:repositories base-package="com.dmitro.repositories" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>
在dispatcher-servlet.xml中,我声明了扫描:
<context:component-scan base-package="com.dmitro.service" />
我正在使用spring-data-jpa 1.8.0.RELEASE版本,请帮忙!