Skip to content

spring-boot-starter-validation and @Validated makes @ConfigurationProperties fail #19638

@peter-lyons-kehl

Description

@peter-lyons-kehl

@ConfigurationProperties(prefix = "validateconfig") and @Component work with org.springframework.boot:spring-boot-autoconfigure:2.2.2.RELEASE: the config bean's fields get populated.

However, if you add @Validated and org.springframework.boot:spring-boot-starter-validation:2.2.2.RELEASE, then the config bean is not populated anymore.

An example to reproduce:

git clone https://github.com/peter-kehl/validate-config-bug-report
cd validate-config-bug-report
./gradlew run

Output (the last two lines - conf value and another conf value show the problem):

 :: Spring Boot ::        (v2.2.2.RELEASE)

2020-01-11 22:34:01.812  INFO 7637 --- [           main] your.pack.App                            : Starting App on spectre with PID 7637 (/home/pkehl/validate-config-java/build/classes/java/main started by pkehl in /home/pkehl/validate-config-java)
2020-01-11 22:34:01.817  INFO 7637 --- [           main] your.pack.App                            : No active profile set, falling back to default profiles: default
2020-01-11 22:34:02.791  INFO 7637 --- [           main] your.pack.App                            : Started App in 1.545 seconds (JVM running for 2.014)
conf is of class class your.pack.Conf$$EnhancerBySpringCGLIB$$f1724790
conf value: null
another conf value: null

To see how the same config bean works without spring-boot-starter-validation, edit build.gradle, comment out the first compile statement, uncomment the second compile statement. Then ./gradlew clean run. The output is similar to the above, except for:

conf is of class class your.pack.Conf
conf value: validateconfigvalue
another conf value: anothervalidateconfigvalue

Potentially related to #8173 or spring-cloud/spring-cloud-commons#177.

(Also reported recently at https://stackoverflow.com/questions/55471653/spring-validated-annotation-prevents-configurationproproperties-value-injectio#comment97662035_55471653

If JDK version matters, I'm on OpenJDK 1.8.0_232-b09, 64-Bit Server VM (build 25.232-b09, mixed mode)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fix

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions