java—如何仅在事务提交后执行方面的方法?

ohtdti5x  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(219)

我有一个带有@transactional method的控制器,它获取一些模型并将其保存在db中,如下所示:

@Controller
@RequiredArgsConstructor
public class TestController {

    private final TestService testService;

    @PostMapping("/test")
    @Transactional
    public void saveTest(TestModel model){
        testService.save(model);
        // some other actions
    }

}

以及这样的服务:

@Service
@RequiredArgsConstructor
public class TestService {

    private final TestReposiory repository;

    @Transactional
    public TestModel save(TestModel model){
        return repository.save(model);
    }
}

我需要一个方面,应该在testservice.save(..)之后执行,如下所示:

@Aspect
public class TestAspect{

    @AfterReturning(value = "execution(* service.TestService.save(..))", returning = "saved")
    public void sendTestModelMsg(TestModel saved) {
        // do something with saved TestModel
    }
}

如何使TestSpect.sendtestmodelmsg(..)仅在提交testcontroller.savetest(..)事务之后执行?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题