I'm looking into using spring-cloud-config
for our project, however I would like to be able to customize the ResourceController
. Using ResponseBodyAdvice
seemed like a good option for this purpose as I would like to modify response body before it is being sent
However I was not able to trigger the RestControllerAdvice
. Reading the javadoc of the annotation
/**
* Allows customizing the response after the execution of an {@code @ResponseBody}
* or a {@code ResponseEntity} controller method but before the body is written
* with an {@code HttpMessageConverter}.
*
* <p>Implementations may be registered directly with
* {@code RequestMappingHandlerAdapter} and {@code ExceptionHandlerExceptionResolver}
* or more likely annotated with {@code @ControllerAdvice} in which case they
* will be auto-detected by both.
*
* @author Rossen Stoyanchev
* @since 4.1
* @param <T> the body type
*/
public interface ResponseBodyAdvice<T> {
..
}
seems that the addition of the annotations or wrapping the response with ResponseBody
would fix the problem. Places where they should be added:
https://github.com/spring-cloud/spring-cloud-config/blob/master/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceController.java#L105
https://github.com/spring-cloud/spring-cloud-config/blob/master/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceController.java#L113
Comment From: spencergibb
It's a @RestController
which already has @ResponseBody
. https://docs.spring.io/spring/docs/5.2.4.RELEASE/javadoc-api/org/springframework/web/bind/annotation/RestController.html
Comment From: stefanvassilev
the misconception was on my side, i got it working :-)
thank you for the fast response
closing issue