avaje-inject
avaje-inject copied to clipboard
Default bean alongside the @Named one
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
.
Yes, this issue should be resolved as part of https://github.com/avaje/avaje-inject/issues/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.
Awesome!