由于@HystrixCommand采用的也是aop切面,且会拦截异常导致事务失效
解决办法,提取事务代码到下一层,保证事务AOP执行
@HystrixCommand(fallbackMethod = "hystirxTest")
public String testTimeout() throws InterruptedException {
testService.test();
return "这是一个provider返回";
}
@Transactional(rollbackFor = Throwable.class)
public void test(){
int i = new Random().nextInt();
jdbcTemplate.execute("insert into my_test (id) values (" + i + ")");
if(true){
throw new RuntimeException();
}
}