I want to return a simple plain text string as follows:
@RestController
@RequestMapping("/test")
public class TestController {
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/my", method = RequestMethod.GET, produces="text/plain")
public String test() {
return "OK";
}
Problem: I also have a global ContentNegotiation filter as follows:
@Configuration
public class ContentNegotiationAdapter extends WebMvcConfigurerAdapter {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false)
.favorParameter(true)
.ignoreAcceptHeader(true)
.useJaf(false)
.defaultContentType(MediaType.APPLICATION_XML);
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
super.configureMessageConverters(converters);
}
}
Result: whenever I access the spring controller, I'm getting the error:
Could not find acceptable representation
Question: how can I force the controller to return plain text, even though only XML was configured within content negotation (which I have to keep)?