As was suggested in https://github.com/spring-projects/spring-boot/issues/16290, creating this follow up issue for a bit different flavor of the same problem. In the original issue, a list of properties contained strings and that case seems to be fixed now, but when we use some custom object instead of string - the problem is still reproducible.
Here is a sample application to reproduce an issue.
Running mvn clean test
fails with:
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.156 s <<< FAILURE! - in com.example.demo.DemoApplicationTests
[ERROR] contextLoads Time elapsed: 0.016 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'demoApplication.DemoProperties': Could not bind properties to 'DemoApplication.DemoProperties' : prefix=demo-properties, ignoreInvalidFields=false, ignoreUnknownFields=false; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'demo-properties' to com.example.demo.DemoApplication$DemoProperties
Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'demo-properties' to com.example.demo.DemoApplication$DemoProperties
Caused by: org.springframework.boot.context.properties.bind.UnboundConfigurationPropertiesException: The elements [demo-properties.nested-data[2].data] were left unbound.
While starting the application itself works fine.
This is because in the application-test.yml
I have a list of properties (nested-data
) overridden with a list, smaller than the original one in the application.yml
According to the documentation I would expect the list from the application-test.yml
to just override one from the application.yml
. Now it looks like it defines a number of elements based on the application.yml
then tries to fill those three elements and fails because there is no data for the third one (because in the application-test.yml
we have only two). Adding the third element to the application-test.yml
fixes the problem.
Comment From: anatoliy-balakirev
@snicoll @mbhave any news on this? Sorry for pinging you, but we've already discussed it in https://github.com/spring-projects/spring-boot/issues/16290 and still this ticket is in "waiting-for-triage" state for 6 days already.
Comment From: snicoll
Sorry, we are very busy at the moment and we'll do our best to triage this one when time permits. Those 6 days are more 3 considering yesterday was a bank holiday in the US and @mbhave is the expert on this topic.
Comment From: mbhave
Sorry I had missed this issue somehow. It is a bug indeed.
Comment From: mbhave
When we fix this, we should ensure that it doesn't fail if demo-properties.nested-data[2].data
is unbound but it does fail if there's a property such as demo-properties.nested-data[2].foo
in application.yml