spring-boot: Failure analysis for a BindException with an unexpected root cause (such as ArrayIndexOutOfBoundsException) is unhelpful

Hi,

I’m using Spring Boot 2.0.2 with Kotlin 1.2.41. I’m trying to use an enum as ConfigurationProperty. I wrote a minimal example application to reproduce the issue: https://github.com/sbueringer/springboot-kotlin-enum/

I have the following ConfigurationProperties:

@Configuration
@ConfigurationProperties(prefix = "custom")
@Validated
class Properties {
    var test = TestEnum.VALUE1
}
enum class TestEnum {VALUE1, VALUE2}

In combination with the following application.yaml:

custom:
  test: VALUE2

I get the following exception on startup:

2018-05-25 06:45:21.848  WARN 22061 --- [  restartedMain] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'application': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'properties': Could not bind properties to 'Properties' : prefix=custom, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'custom.test' to com.example.TestEnum

To reproduce, just clone the repository and startup the SpringBootApplication.

Edit: It seems to work, if I remove the @Validated annotation. Is that intended?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

I’m referring to the obscure error message. The Kotlin support’s new in Framework 5 and Boot 2.0 so it won’t be a possible cause of the obscure error message. While the exception comes from the binder, the error message comes from BindFailureAnalyzer. It exists in 1.5 and 2.0, although it’s not the same in each, and the input will be different hence the need to check what happens in 1.5.