- Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
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