I'm trying to have spring automatically return HTTP Status 204 when the controller method response type is void. Ex:
Let's say I have a controller method like this:
@DeleteMapping(value = "/{heroId}")
public void delete(@PathVariable Long heroId) {
heroService.delete(heroId);
}
I'm looking for a way to automatically return 204 without having to annotate the method with @ResponseStatus(value = HttpStatus.NO_CONTENT).
Is it possible to do this with a handler or AOP or some other facility?
PS. I see this answer, Return HTTP 204 on null with spring @RestController, but does not answer my specific question on how this can be implemented for methods with a void return type. Also, this method should work with a method that has no input arguments.