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

Default bean alongside the @Named one #555

Closed
kliushnichenko opened this issue Apr 30, 2024 · 2 comments · Fixed by #562
Closed

Default bean alongside the @Named one #555

kliushnichenko opened this issue Apr 30, 2024 · 2 comments · Fixed by #562
Assignees
Milestone

Comments

@kliushnichenko
Copy link

I am wondering if it is possible to support the next configuration

@Factory
public class Configuration {

    @Bean
    public Jdbi jdbi() {
        return Jdbi.create(dataSource);
    }

    @Bean
    @Named("asyncJdbi")
    public Jdbi asyncJdbi() {
        return Jdbi.create(asyncDataSource);
    }
}
@Singletone
public class Service {

    @Inject
    public Service(Jdbi jdbi, @Named("asyncJdbi") Jdbi asyncJdbi) { ... }

}

At the moment, the configuration above results in an exception:

Caused by: java.lang.IllegalStateException: Expecting only 1 bean match but have multiple matching beans org.jdbi.v3.core.Jdbi@5a2035e1 and org.jdbi.v3.core.Jdbi@5a2035e1. Maybe need a rebuild is required after adding a @Named qualifier?  

It forces all beans of the type to be annotated with @Named, which is not always convenient. I suggest supporting a default bean that can remain un-@Named.

Same story with @Qulifier.

@rbygrave
Copy link
Contributor

Yes, this issue should be resolved as part of #543 ... (which is having a default for the unqualified but also preferring "same module" wiring for the multi-module case). So yes I am expecting the PRs in progress for that issue to also resolve this issue.

@kliushnichenko
Copy link
Author

Awesome!

rbygrave added a commit that referenced this issue May 6, 2024
…ed bean)

In the case where we have 2 beans of the same type and one has no qualifier,
then when injecting a bean with no qualifier specified then prefer to wire
the bean with no qualifier.

Example: In the MegaStoreManager example we have NoNameStore as a bean with
no name qualifier and that is preferred for the noQualifier injection point.
rbygrave added a commit that referenced this issue May 6, 2024
…ed bean) (#562)

In the case where we have 2 beans of the same type and one has no qualifier,
then when injecting a bean with no qualifier specified then prefer to wire
the bean with no qualifier.

Example: In the MegaStoreManager example we have NoNameStore as a bean with
no name qualifier and that is preferred for the noQualifier injection point.
@rbygrave rbygrave self-assigned this May 6, 2024
@rbygrave rbygrave added this to the 10.0 milestone May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants