I have the following code which works well when I use it in my Quarkus application:
public interface CrudRepository<T> {
void save(T t);
Set<T> findAll();
Set<T> findByMapOfKeyValues(T t);
}
public class CrudRepositoryImplementation<T> implements CrudRepository<T> {
private T t;
@Override
public void save(T t) {
// some impl
mapper.save(t);
}
@Override
public Set<T> findAll() {
//some impl
return new HashSet<>(mapper.query((Class<T>) t.getClass(), queryExpression));
}
@Override
public Set<T> findByMapOfKeyValues(T t) {
//some impl
return new HashSet<>(mapper.query((Class<T>) t.getClass(), queryExpression));
}
}
Using a producer method as shown below to indicate quarkus for CDI to be done:
public class Config {
@Produces
@Dependent
public <T> CrudRepository<T> getCrudRepo() {
return new CrudRepositoryImplementation<>();
}
}
When i run the above in a package in my application and I inject the interface CrudRepository as shown below, everything works fine:
@ApplicationScoped
public class VehicleService {
@Inject
CrudRepository<Vehicle> repository;
public void saveEVBattery(String vin){
//some impl
}
Now the issue is when i build the package in a separate maven project and import it as a dependecy in my quarkus application, i get the following error. As per my observation, i think quarkus is not calling the producer method at runtime and thus it does not get the implmentation to inject it.
pom.xml
<dependency>
<groupId>com.repo.dynamodb</groupId>
<artifactId>CrudRepositoryDynamoDB</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Exception thrown at runtime:
Build failure: Build failed due to errors
[ERROR] [error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.e
nterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type com.repo.dynamodb.CrudRepository<Vehicle> and qualifiers [@Default]
Can you guide me into how to successfully inject my jar into my Quarkus Application on runtime?