Skip to content

Conversation

@mcruzdev
Copy link
Contributor

@mcruzdev mcruzdev commented Feb 7, 2025

Fixes #45961

This pull request aims to solve an issue when using @Named annotation.

Having the following code below:

@Configuration
public class MyConfiguration {
    @Bean("mySpecialName")
    public String foo() {
        return "foo";
    }
}

The Quarkus SpringDIProcessor will add @Named("foo") (the method name) instead of @Named("mySpecialName") (the bean name), and we will get an UnsatisfiedResolutionException.

This should work properly, getBeanNameFromBeanInstance in SpringDIProcessor does check the value of the @bean annotation to place the correct @Named annotation on the method, but it has a small error: this if statement checks if beanNameAnnotationValue != null instead of if beanValueAnnotationValue != null (beanName vs beanValue).

This change uses the value instead the name, removing the UnsatisfiedResolutionException.

@quarkus-bot quarkus-bot bot added the area/spring Issues relating to the Spring integration label Feb 7, 2025
@quarkus-bot

This comment has been minimized.

@geoand geoand requested a review from mkouba February 7, 2025 15:04
Copy link
Contributor

@mkouba mkouba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks reasonable but I did not check the other parts of the SpringDIProcessor and how exactly we map spring annotations to @Named...

Also pls squash the commits and maybe add a more "informative" commit description.

@mcruzdev
Copy link
Contributor Author

mcruzdev commented Feb 7, 2025

Yes @mkouba I will do it. It had to be a draft

@quarkus-bot
Copy link

quarkus-bot bot commented Feb 15, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 37dc798.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@gsmet gsmet changed the title Fix Named beans Spring DI - Fix behavior with named beans Feb 17, 2025
Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the fix!

@gsmet gsmet merged commit 221e4b2 into quarkusio:main Feb 17, 2025
23 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.21 - main milestone Feb 17, 2025
@gsmet gsmet modified the milestones: 3.21 - main, 3.19.0 Feb 18, 2025
@gsmet gsmet modified the milestones: 3.19.0, 3.18.4 Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/spring Issues relating to the Spring integration kind/bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

quarkus-spring-di: @Bean("foo") is not transformed into the proper @Named("foo") annotation

4 participants