-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Autowiring of a generic type produced by a factory bean fails after AOT processing #29385
Comments
I tentatively add this one for 6.0 GA since that breaking some propular use cases. |
Things have improved, but the problem isn't fully resolved. While the slightly simplified reproducer now passes, the other test in the sample still fails:
As before, this test passes when AOT processing is not enabled. |
With the recent changes, |
This failure to match the generics can be reproduced by changing the type of the static class Consumer {
@Autowired
JacksonTester<Request> tester;
} This then fails as |
Thanks, Andy. This is probably not related to the original |
Andy, with the injection point changed as above, if the AOT-determined target type is then also set to I do wonder why we keep having such non-matching generics to begin with. In an ideal world, we would not need the lenient fallback match at all anymore. That said, I'm currently looking into how to let it kick in even for a pre-determined target type. |
I got an arrangement for this now where for pre-determined FactoryBean types, we only take the resolved Class in a fallback match, which is equivalent to how lazy type determination for FactoryBeans proceeds in a fallback scenario. I'll push this shortly. |
@wilkinsona This should be addressed in the upcoming snapshot now. Please let me know whether it works for Boot... |
Affects: 6.0.0-RC2
We found this problem when testing Spring Boot's
JacksonTester
support but I believe it's a general AOT problem to do with factory beans that produce a generic type. Here's a small sample that reproduces the problem:factory-bean-problem.zip
./gradlew test
should result in two failures:The first reproduces the problem that we've seen in Spring Boot. If you edit
build.gradle
to comment out the setting of thespring.aot.enabled
system property and run./gradlew test
again,contextLoads()
should pass. The second is an attempt to reproduce the problem in a minimal (and slightly simplified) manner. It doesn't involve Boot or the Test Framework at all.From what I have seen in the debugger, the behavior diverges in
GenericTypeAwareAutowireCandidateResolver.checkGenericTypeMatch(BeanDefinitionHolder, DependencyDescriptor)
. In the Java config case, the target type is determined via aBeanFactory.getType
call:spring-framework/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java
Lines 107 to 110 in 997dd3e
This is sufficient for the result of the check to be
true
and for autowiring to succeed.In the AOT-processed case, the target type is available from the bean definition:
spring-framework/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericTypeAwareAutowireCandidateResolver.java
Line 90 in 997dd3e
As a result, the
getType
call on the bean factory never happens. The result of the check is false and autowiring fails.The text was updated successfully, but these errors were encountered: