【发布时间】:2019-11-22 17:30:00
【问题描述】:
我想在调用执行器端点 /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]
但是,当我在 Chrome 中触发相同的 url 时,我会收到有效的响应。
在我的情况下,执行器应该在没有标题的情况下调用(没有 -H 'Accept: ...')
【问题讨论】:
-
configurer.ignoreAcceptHeader(true)是否满足您的需求? -
不,我仍然需要能够发送带有标头的 GET 请求,例如-H '接受:应用程序/json' 和 xml
标签: java spring-boot spring-boot-actuator content-negotiation