I have a (simplified below) RestController invoking a 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> {
}
I'd like to do some additional stuff after the entity (car in this case) is saved.
I tried using @RepositoryEventHandler
and AbstractRepositoryEventListener
but, as stated here, these only work when invoked by the CrudRepository exposed REST. Meaning, not working when invoked programmatically.
Any idea how to listen to repository events, regardless of how they are invoked?