次のように単純なプレーンテキスト文字列を返したい:
@RestController
@RequestMapping("/test")
public class TestController {
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/my", method = RequestMethod.GET, produces="text/plain")
public String test() {
return "OK";
}
問題: 次のようなグローバル ContentNegotiation フィルターもあります。
@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);
}
}
結果: スプリング コントローラーにアクセスするたびに、次のエラーが発生します。
Could not find acceptable representation
質問: コンテンツ ネゴシエーション (保持する必要がある) 内で XML のみが構成されている場合でも、コントローラーがプレーン テキストを返すように強制するにはどうすればよいですか?