Skip to content
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

Qualifiers registered programmatically are not supported by AOT #30410

Closed
DanielThomas opened this issue May 2, 2023 · 4 comments
Closed

Qualifiers registered programmatically are not supported by AOT #30410

DanielThomas opened this issue May 2, 2023 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@DanielThomas
Copy link

Qualifiers aren't captured by AOT in the generated BeanDefinitions classes, leading to failures when running under AOT:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.example.demo.DemoApplication$RequiresGrpcClient required a bean of type 'com.example.demo.DemoApplication$GrpClient' that could not be found.

The injection point has the following annotations:
	- @com.example.demo.GrpcSpringClient("myclient")

The following candidates were found but could not be injected:
	- User-defined bean


Action:

Consider revisiting the entries above or defining a bean of type 'com.example.demo.DemoApplication$GrpClient' in your configuration.

In our specific case, they're custom qualifier annotations and definitions registered by a registry post-processor. It appears for simple annotated Qualifier beans, the framework is able to fallback and infer the qualifier.

Example project:

https://github.com/DanielThomas/spring-aot-issues/tree/dannyt/qualifier-missing

Run and note the failure:

./gradlew bootJar && java -Dspring.aot.enabled=true -jar build/libs/demo-0.0.1-SNAPSHOT.jar
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 2, 2023
@sdeleuze
Copy link
Contributor

sdeleuze commented May 2, 2023

To be checked if #29709 is related or not.

@snicoll
Copy link
Member

snicoll commented May 2, 2023

In our specific case, they're custom qualifier annotations and definitions registered by a registry post-processor.

Static qualifiers are supported as you've found out. We haven't had a use case of something like this being set programmatically. Thanks for the reproducer!

@snicoll snicoll added in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing labels May 2, 2023
@snicoll snicoll self-assigned this May 2, 2023
@snicoll snicoll changed the title Qualifiers not supported by AOT Qualifiers registered programmatically are not supported by AOT May 2, 2023
@snicoll
Copy link
Member

snicoll commented May 3, 2023

It looks like we should support a form of AutowireCandidateQualifier where any value we can handle with AOT is actually written in code. I don't know if we can short-circuit the algorithm that checks for the @Qualifier annotation, but it's worth a try.

@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 3, 2023
@snicoll snicoll added this to the 6.0.x milestone May 3, 2023
snicoll added a commit to snicoll/spring-framework that referenced this issue May 3, 2023
This commit handles AutowiredCandidateQualifier instances, rather than
relying on qualifiers being statically defined and meta-annotated with
`@Qualifier`.

Closes spring-projectsgh-30410
@snicoll
Copy link
Member

snicoll commented May 3, 2023

I think I have a fix for this with snicoll@2f41ce6. Building your reproducer with it adds the following line to the bean definition.

beanDefinition.addQualifier(new AutowireCandidateQualifier("com.example.demo.GrpcSpringClient", "myclient"));

I'd like to spend a bit more time on what we do for @Qualifier and the impact processing those may have. But I am hopeful to get a fix for 6.0.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants