どのように春のアクチュエータのための無効化コンテンツネゴシエーションに?

アレックス:

私はとき、アクチュエータのエンドポイントを無効にコンテンツネゴシエーションしたい/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);
        }
    });       
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=363088&siteId=1