Hello everyone,
I hope you are doing well. I am currently working with CDI (Contexts and Dependency Injection) in both CDI-Lite and CDI-Full environments, and I have encountered an issue that I am seeking assistance with. I have followed the CDI specification and have used a Java Annotation processor to generate code.
Here’s a simplified example of what I have done:
- I have an interface called
ProductRepository
annotated with @Repository
.
@Repository
public interface ProductRepository extends PageableRepository<Product, String> {
}
- Using a Java Annotation processor, the implementation class
ProductRepositoryLiteDocument
is generated:
@Generated(value= "JNoSQL Lite Document Repository Generator", date = "2023-08-15T11:04:47.536505")
@jakarta.enterprise.context.ApplicationScoped
@jakarta.enterprise.inject.Default
@org.eclipse.jnosql.mapping.Database(value = org.eclipse.jnosql.mapping.DatabaseType.DOCUMENT)
public class ProductRepositoryLiteDocument implements org.jnosql.demo.se.ProductRepository {
}
- I’ve also added a BuildCompatibleExtension called
LiteBeanExtension
to register the class implementation:
public class LiteBeanExtension implements BuildCompatibleExtension {
@Discovery
public void addBeans(ScannedClasses classes) {
classes.add("org.jnosql.demo.se.ProductRepositoryLiteDocument");
}
}
However, when I attempt to run my application to the CDI-full, I encounter the following exception related to ambiguous dependencies:
Exception in thread "main" org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001335: Ambiguous dependencies for type ProductRepository with qualifiers
Possible dependencies:
- Managed Bean [class org.jnosql.demo.se.ProductRepositoryLiteDocument] with qualifiers [@Default @Database @Any],
- Managed Bean [class org.jnosql.demo.se.ProductRepositoryLiteDocument] with qualifiers [@Default @Database @Any]
I have consulted the CDI specification, specifically the section on Bean Class discovery, but it does not seem to address this scenario directly.
My questions are:
- Have I missed something in my implementation that might be causing this ambiguity issue?
- Given my setup, is there a known solution or best practice for ensuring compatibility with CDI-Lite and CDI-Full, specifically when working with extensions?
I appreciate any insights or guidance you can give me about this.
Thank you in advance for your help.