我了解通过使用Actuator,我们必须使用Jackson而不是Gson:
当首选json映射器是Gson时,某些执行器端点将被破坏。重现步骤:
编辑pom.xml
,添加gson依赖项
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
编辑application.properties
management.endpoints.web.exposure.include=*
spring.http.converters.preferred-json-mapper=gson
GET /actuator/beans
,它将遇到500 Internal Server Error with log:
WARN 14692 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Attempted to serialize java.lang.Class: org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor. Forgot to register a type adapter?; nested exception is java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvokerAdvisor. Forgot to register a type adapter?
获取/actuator/mapping
,它也会遇到另一个错误。
如何让应用程序代码使用Gson,又让执行器使用Jackson?