Skip to content

Unable to inject bean by property name #33357

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

Closed
funky-eyes opened this issue Aug 9, 2024 · 4 comments
Closed

Unable to inject bean by property name #33357

funky-eyes opened this issue Aug 9, 2024 · 4 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@funky-eyes
Copy link
Contributor

Affects: <Spring Framework version>
6.x


I encountered an issue where method parameter beans are not injected correctly after upgrading from Spring Boot 2.7.18 to 3.3.2

Error creating bean with name 'androidEngineV3' defined in class path resource [xx/xx/brick/engine/android/AndroidEngineAutoConfiguration.class]: Unsatisfied dependency expressed through method 'androidEngineV3' parameter 0: No qualifying bean of type 'xx.xx.brick.parser.token.TokenIdService' available: expected single matching bean but found 2: defaultTokenIdService,compressTokenIdService
    @Bean
    @ConditionalOnMissingBean(name = "androidEngineV3")
    public DeviceEngine androidEngineV3(TokenIdService defaultTokenIdService,
                                        ....) {
        AndroidEngine androidEngineV3 = new AndroidEngine();
        ....
        return androidEngineV3;
    }

image

Everything worked fine with Spring Boot 2.7.18 and Spring 5.3.x, but after the upgrade, I am experiencing issues with dependency injection. Could you please help me with this problem? Thank you
When I use @qualifier, the issue is resolved, but making this change would require modifying too much code.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 9, 2024
@snicoll
Copy link
Member

snicoll commented Aug 9, 2024

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Aug 9, 2024
@snicoll snicoll added for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 9, 2024
@sbrannen
Copy link
Member

sbrannen commented Aug 9, 2024

Hi @funky-eyes,

It looks like you might not be compiling your code with the -parameters flag.

Please see the Parameter Name Retention notes in the Wiki for details.

If that solves the issue for you, it would be nice if you posted a comment here to confirm that.

Cheers,

Sam

@funky-eyes
Copy link
Contributor Author

Hi @funky-eyes,

It looks like you might not be compiling your code with the -parameters flag.

Please see the Parameter Name Retention notes in the Wiki for details.

If that solves the issue for you, it would be nice if you posted a comment here to confirm that.

Cheers,

Sam

Thank you for your reply @sbrannen . I tried adding the following configuration during compilation, but for some reason it didn’t have any effect. However, it worked fine when I reverted to version 2.7. I will continue to investigate. If there are any updates, I will provide them in this issue. Regardless of the outcome, thank you both for your help.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <parameters>true</parameters>
    </configuration>
</plugin>

@funky-eyes
Copy link
Contributor Author

Hi @sbrannen
I tried many times, and I ensured that I added true in the maven-compiler-plugin, but it still had no effect. I downgraded Spring Boot to version 3.0.11, and my program ran successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

4 participants