无法在 Spring Boot 2 中绑定 Zipkin 枚举

Unable to bind a Zipkin enum in Spring Boot 2

我正在将应用程序升级到 Spring Boot 2.1.3(从 1.5.x),我在启动时遇到问题。下面的块无法正确绑定:

  spring:
    zipkin:
      enabled: true
      base-url: http://myZipkinServer
      sender:
        type: web

我收到此错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'spring.zipkin.sender.type' to org.springframework.cloud.sleuth.zipkin2.sender.ZipkinSenderProperties$SenderType:

Property: spring.zipkin.sender.type
Value: web
Origin: class path resource [application.yml]:68:13
Reason: 0

Action:

Update your application's configuration

在我收到 WARN 日志宣布该问题之前:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'spring.zipkin.sender-org.springframework.cloud.sleuth.zipkin2.sender.ZipkinSenderProperties': Could not bind properties to 'ZipkinSenderProperties' : prefix=spring.zipkin.sender, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.zipkin.sender.type' to org.springframework.cloud.sleuth.zipkin2.sender.ZipkinSenderProperties$SenderType

我正在尝试进行调试,但我最终深入 Spring 引导内部 在 org.springframework.boot.context.properties.bind.Binder 中。 我有一个类似的应用程序,或多或少具有相同的版本,它工作得很好。我试图找到不同之处,比较执行流程,但没有发现任何明显的东西。

在 IntelliJ 中,我获得了自动完成功能,因此我知道我的 yaml 格式正确:"web" 值是向我建议的。

知道如何调查此类问题吗?

好吧,经过几个小时的努力,我取得了一些进展,现在应用程序启动了——尽管此时我还不完全清楚问题的根本原因。 以下是我的发现:

  • 我注意到一件奇怪的事:如果我将 sender.typeweb 更改为 rabbit,那么应用程序将正常启动。

  • 我还发现了这个 Spring 引导 issue report,与我的非常相似,它指向一个 JDK 错误。事实上,从 jdk1.8.0_25 升级到 jdk1.8.0_201 .

  • 最后,我还发现,如果我使用的是 jdk1.8.0_25 而根本没有提供 sender.type,那么该应用程序也可以正常启动。

出于某种原因,在我拥有的另一个应用程序中,我可以使用 jdk1.8.0_25sender.type: web

如果有人有快速解决此类问题的方法,请不要犹豫,将其添加到评论中或编辑此答案。