【发布时间】:2018-08-02 17:35:22
【问题描述】:
我有一个(下面简化的)RestController 调用 CrudRepository。
@RestController
@RequestMapping({"/carApi"})
public class RestService {
@Autowired
private StorageService storageService;
@PostMapping
public RightTriangle create(@RequestBody DegregatedCar degregatedCar) {
// Some logic
Car car = convert(degregatedCar);
return storageService.save(car);
}
}
public interface StorageService extends CrudRepository<Car, Long> {
}
我想在实体(本例中为汽车)保存后做一些额外的事情。
我尝试使用@RepositoryEventHandler 和AbstractRepositoryEventListener,但是,如here 所述,它们仅在被暴露在CrudRepository 的REST 调用时才有效。意思是,以编程方式调用时不起作用。
知道如何监听存储库事件,不管它们是如何被调用的?
【问题讨论】:
-
你在用mongo吗?
标签: spring-boot events event-handling crud