Skip to content

Failure analysis for a BindException with an unexpected root cause (such as ArrayIndexOutOfBoundsException) is unhelpful #13258

@sbueringer

Description

@sbueringer

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?

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions