New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@ConfigurationProperties @ConstructorBinding sets missing Optional to null #21795
Comments
The current behavior of injecting The use of |
I think IntelliJ even warns you about
So it's mainly about having a more expressive way for returns with "no result". Since Optional isn't Serializable there is also the problem that it shouldn't be used in bean like classes. |
https://www.youtube.com/watch?v=Ej0sss6cq14 is a good talk by Stuart Marks about Optional in general. |
With immutable configuration properties as described at https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-constructor-binding
Optional
doesn't work as expected.Using Spring Boot 2.3.0:
Using
application.properties
:Expected:
monitorConfiguration.managerUrl
should be Optional.EMPTYThis behavior would match the non-immutable ConfigurationProperties behavior described in #5110
Actual:
monitorConfiguration.managerUrl
is nullNote that #18917 says this issue should have already been fixed in Spring Boot 2.3.0, but that's not what I'm seeing.
If I add
@DefaultValue
to theOptional<String> managerUrl
parameter in the contructor, then I get the expected behavior - but IMHO, the@DefaultValue
should not be necessary.The text was updated successfully, but these errors were encountered: