You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@ConfigurationProperty validation is great as it forces the application to not start if properties are invalid or missing. However, there is a case of partially missing properties that does not work as I expected.
Spring Boot version: 2.1.1.RELEASE
Java version: 1.8
Steps to reproduce
Consider the following web app which exposes the property app.value at the endpoint /:
Assume I provide partially missing configuration in my application.yml as follows:
app:
The application comes up and exposes a null value:
➜ ~ curl localhost:8080/
The configured value is 'null'.%
What I would have expected is the same behaviour as for the following case. If I either fail to provide any configuration - application.yml is empty - or fail to provide the value
app:
value:
... then (as expected) the application fails to come up
***************************
APPLICATION FAILED TO START
***************************
Description:
Binding to target org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'app' to io.github.mamachanko.configurationpropertyvalidation.Config$$EnhancerBySpringCGLIB$$e06d273 failed:
Property: app.value
Value: null
Reason: must not be blank
Action:
Update your application's configuration
Am I missing an annotation or setting to also fail in the odd case?
Thanks!
The text was updated successfully, but these errors were encountered:
mamachanko
changed the title
@ConfigurationProperty validation not working for missing property
@ConfigurationProperty validation not working for partially missing property
Jan 2, 2019
mamachanko
changed the title
@ConfigurationProperty validation not working for partially missing property
@ConfigurationProperty validation not working for partially missing yaml
Jan 2, 2019
@mamachanko thanks for the report, it looks like validation does not work properly if a property with key app is set in the Environment (it doesn't matter the value, I've tried app=test and it fails the same way). I've also reproduced the problem without yaml to confirm this isn't yaml specific.
(Side note, please do not flag your @ConfigurationProperties bean as @Configuration: these are not configuration classes providing @Bean definitions but regular @Component classes that are bound to the Environment).
snicoll
changed the title
@ConfigurationProperty validation not working for partially missing yaml
@ConfigurationProperty validation not working when a key matching the prefix is set
Jan 2, 2019
@ConfigurationProperty
validation is great as it forces the application to not start if properties are invalid or missing. However, there is a case of partially missing properties that does not work as I expected.2.1.1.RELEASE
1.8
Steps to reproduce
Consider the following web app which exposes the property
app.value
at the endpoint/
:Assume I provide partially missing configuration in my
application.yml
as follows:app:
The application comes up and exposes a null value:
What I would have expected is the same behaviour as for the following case. If I either fail to provide any configuration -
application.yml
is empty - or fail to provide the value... then (as expected) the application fails to come up
Am I missing an annotation or setting to also fail in the odd case?
Thanks!
The text was updated successfully, but these errors were encountered: