アレックス:
私はとき、アクチュエータのエンドポイントを無効にコンテンツネゴシエーションしたい/info
と/health
呼ばれています
ここに私のconfigsファイルがあります
@Configuration
public class InterceptorAppConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(interceptor);
}
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_XML)
.mediaType("json", MediaType.APPLICATION_JSON)
.mediaType("xml", MediaType.APPLICATION_XML);
}
}
とき私は、 curl http://localhost:8081/health
私は受け取ります:
DefaultHandlerExceptionResolver Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]
私はChromeで同じURLを発射するときしかし、私は有効な応答を受け取ります。
私の場合、アクチュエータは、ヘッダーなしで呼び出されるべきです(何-H「受け入れません:...」)
Pasupathi Rajamanickam:
追加defaultContentTypeStrategy
とヌルを処理またはワイルドカード。
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_XML)
.mediaType("json", MediaType.APPLICATION_JSON)
.mediaType("xml", MediaType.APPLICATION_XML);
configurer.defaultContentTypeStrategy(new ContentNegotiationStrategy() {
@Override
public List<MediaType> resolveMediaTypes(NativeWebRequest webRequest) throws HttpMediaTypeNotAcceptableException {
// If you want handle different cases by getting header with webRequest.getHeader("accept")
return Arrays.asList(MediaType.APPLICATION_JSON);
}
});
}