The following works in Spring Boot 3.3 (and with Spring Framework overridden to 6.2.2), but fails in 3.4.2
application.yml:
app:
property: {}
@Validated
@ConfigurationProperties(prefix = "app")
public record MyProperties(
@NotNull Map<String, MyPojo> configs) {}
Debugging, I find that a breakpoint at the return point org.springframework.boot.env.OriginTrackedYamlLoader#load
then we have one less key in the result:
In 3.3 then there is an entry with {} as the value:
but in 3.4, there isn't.
Comment From: wilkinsona
This is an intentional change. Please see https://github.com/spring-projects/spring-boot/issues/43437 and https://github.com/spring-projects/spring-boot/issues/35403 for the background. You should be able to use @DefaultValue
to request that the binder creates an empty configs
map. Note that the binder's never considered @NonNull
and I believe you'll see the same behavior with or without it.