-
Notifications
You must be signed in to change notification settings - Fork 38.1k
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
AOT processing fails for @ConfigurationProperties
class without default constructor
#31117
Comments
Introduce a default constructor to prevent the AOT engine from breaking as reported in [0]. [0] spring-projects/spring-framework#31117
Introduce a default constructor to prevent the AOT engine from breaking as reported in [0]. [0] spring-projects/spring-framework#31117
@ConfigurationProperties
class without default constructor
Seems to be caused by the fact that Not sure yet how to fix this, should Spring Framework provide an extension point that Spring Boot would leverage? |
I think the constructor or factory method's only actually going to be used to determine the class name of the target:
The implementation of |
Looking at other use of it, there's the only thing I am not too fan is that users would then have to override |
This is surprisingly difficult. The code that uses the |
This commit allows a custom code fragment to provide the code to create a bean without relying on ConstructorResolver. This is especially important for use cases that derive from the default behaviour and provide an instance supplier with the regular runtime scenario. This is a breaking change for code fragments providing a custom implementation of the related methods. As it turns out, almost all of them did not need the Executable argument. Configuration class parsing is the exception, where it needs to provide a different constructor in the case of the proxy. To make this use case possible, InstanceSupplierCodeGenerator has been made public. Closes spring-projectsgh-31117
I have something that works but is a breaking change for anyone implementing @jhoeller wondering if that's acceptable to break the interface in 6.1. The alternative is to reintroduce the previous methods with a default implementation that returns |
Unfortunately, I had to go with the breaking change as keeping the original method meant that the executable had to be resolved before calling it and check if it was actually implemented by a custom code fragment. It's unfortunate but acceptable given the scope of this API. |
This commit adapts to API changes in Spring Framework, see spring-projects/spring-framework#31117 Previously, the "autowired" executable to use for a bean was always resolved, even if a custom code fragment didn't really need it. This is key for binding of immutable configuration properties as we use an instance supplier for it. This changes means that the workaround added in maintenance releases can be removed. See gh-37337
During AOT processing, the constructor detection for AOT fails for configuration properties classes that do not declare a default constructor. An example can be found in Spring RESTBucks for
MomentsProperties
.Steps to reproduce:
The output is the following stack trace:
ConstructorResolver.resolveConstructor(…)
is given an empty list of value type, as the bean definition for a configuration properties class doesn't have any constructor arguments registered. It will then process the existing complex constructors and disregard them all as they do not match the empty value types.The problem was originally reported here. To solve that I can work around the problem by adding a default constructor to
MomentsProperties
. The reproducer works if built with that change in place.The text was updated successfully, but these errors were encountered: