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

Reinstate qualifier support for legacy JSR-330 @javax.inject.Named annotation #33345

Closed
marcioscharamtrustly opened this issue Aug 7, 2024 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@marcioscharamtrustly
Copy link

marcioscharamtrustly commented Aug 7, 2024

Affects: Spring Boot 3.2.5, Spring 6.1.6. Also tested with Spring Boot 3.2.8

We have a project which we have some modules using javax/Guice and others with Spring Boot. Now we're upgrading from Spring Boot 2.7.18 to 3.2.5, but we're having some problems related to javax.inject.Named.

Our code has a "common" module with services/repositories which is used in both Guice and Spring Boot, and for that we're using @Named/@Inject in the classes.

In version 2.7.18 all is working fine, but when we upgraded to 3.2.5 we started receiving an error when injecting dependencies on a class. The class has 2 parameters in the constructor, both of an interface and using @Named("nameOfBean") to distinguish between the expected implementation to be injected, and we have the two related implementations.

I created a simple project to reproduce the problem and share with you. I tried changing some dependencies and nothing solved the problem.
I tried changing all to jakarta.*, and then all worked fine. But, that's not an option right now because of project context.

The project is in https://github.com/marcioscharamtrustly/TestSpringBootJavax

A lille more about the problem: It appears that Spring identifies @Named and knows how to handle and inject it. But it doesn't work well when the parameters expect a @Named("name").

And we're based on this issue: #31090

The error I'm receiving when running TestSpringBootJavaxApplication is:

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

Description:

Parameter 0 of constructor in any.javax.code.Service required a single bean, but 2 were found:
	- ONE: defined in file [/Users/marcio.scharam/TestSpringBootJavax/javax-module/target/classes/any/javax/code/OneRepository.class]
	- TWO: defined in file [/Users/marcio.scharam/TestSpringBootJavax/javax-module/target/classes/any/javax/code/TwoRepository.class]

This may be due to missing parameter name information

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Ensure that your compiler is configured to use the '-parameters' flag.
You may need to update both your build tool settings as well as your IDE.
(See https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention)

Process finished with exit code 1

We also tested using maven-compiler-plugin 3.13.0, setting the true as suggested here: https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 7, 2024
@snicoll snicoll transferred this issue from spring-projects/spring-boot Aug 8, 2024
@sbrannen sbrannen changed the title Problem injecting @Named("name") from javax.inject.Named in Spring Boot 3.2.5 Problem injecting @javax.inject.Named("name") in Spring Framework 6.1.x Aug 8, 2024
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Aug 8, 2024
@sbrannen
Copy link
Member

sbrannen commented Aug 8, 2024

It looks like we'd need to reintroduce support for javax.inject.Qualifier in QualifierAnnotationAutowireCandidateResolver, like we did for jakarta.inject.Named in #31090.

@sbrannen sbrannen self-assigned this Aug 8, 2024
@sbrannen sbrannen changed the title Problem injecting @javax.inject.Named("name") in Spring Framework 6.1.x Reinstate qualifier support for legacy JSR-330 @javax.inject.Named annotation Aug 8, 2024
@sbrannen sbrannen added this to the 6.1.12 milestone Aug 8, 2024
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 8, 2024
@sbrannen
Copy link
Member

sbrannen commented Aug 8, 2024

Hi @marcioscharamtrustly,

Congratulations on submitting your first issue for the Spring Framework! 👍

And thanks for the detailed description and sample project.

This has been addressed for inclusion in the upcoming Spring Framework 6.1.12.

@marcioscharamtrustly
Copy link
Author

Glad to help and thank you all by the fast analysis and response.

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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants