Я хотел бы отключить Content-Negotiation, когда вызываются конечные точки исполнительного механизма /info
и /health
вот мой файл конфигурации
@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]
Однако, когда я запускаю тот же URL-адрес в Chrome, я получаю правильный ответ.
В моем случае привод должен вызываться без заголовков (без -H 'Accept: ...')
configurer.ignoreAcceptHeader(true)
соответствует вашим потребностям? - person Dirk Deyne   schedule 22.11.2019