问题:spring的service中抛出异常后不回滚?
Spring事务: 在默认情况下,Spring的容器对于非受查异常(服务模块中抛出的非受查异常),会回滚事务。对于受查异常,会提交事务。 对于Spring来说, Spring的声明式事务可以设置事务边界(传播行为),设置隔离级别,设置只读事务,回滚规则(+:对于任何异常都提交,-:对于任何异常都回滚) <property name=”transactionAttributes”> <props> <prop key=”*”>+异常类型1,-异常类型2</prop> </property>
例子: bean id="transactionAttributes" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource"> <property name="properties"> <value> do*=PROPAGATION_REQUIRED,-Exception get*=PROPAGATION_REQUIRED,readOnly search*=PROPAGATION_REQUIRED,readOnly </value> </property> </bean> 加上-Exception