Spring Boot Actuator 需要 @EnableWebMvc 但会关闭其他功能
Spring Boot Actuator requires @EnableWebMvc but that turns off other features
我在尝试使用 Spring Boot 1.5.11 的静态资源服务功能将 Actuator 集成到项目时感到困惑:
Spring Boot Actuator 在没有 @EnableWebMvc
的情况下无法工作,返回 HTTP 406,因为没有安装正确的 Http 媒体转换器。
但如果我添加 @EnableWebMvc
,它会关闭 static
文件夹和其他 Spring 引导功能的服务资源。
有没有办法在不丢失 Boot 功能的情况下初始化 Actuator?
在 Spring Boot 2.0 中发现了一个 bug,似乎在 Boot 1.5 中也有。解决方法:将 favorPathExtension
设置为 false
会关闭 ServletPathExtensionContentNegotiationStrategy
中的错误代码,并且执行器端点开始工作。
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}
我在尝试使用 Spring Boot 1.5.11 的静态资源服务功能将 Actuator 集成到项目时感到困惑:
Spring Boot Actuator 在没有
@EnableWebMvc
的情况下无法工作,返回 HTTP 406,因为没有安装正确的 Http 媒体转换器。但如果我添加
@EnableWebMvc
,它会关闭static
文件夹和其他 Spring 引导功能的服务资源。
有没有办法在不丢失 Boot 功能的情况下初始化 Actuator?
在 Spring Boot 2.0 中发现了一个 bug,似乎在 Boot 1.5 中也有。解决方法:将 favorPathExtension
设置为 false
会关闭 ServletPathExtensionContentNegotiationStrategy
中的错误代码,并且执行器端点开始工作。
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false);
}
}