我正在尝试通过名为MongoQuery的CDI管理一个类,该类包含用于查询MongoDB的逻辑。这将需要来自通过ArC CDI(针对substrateVM的Quarkus风味CDI实现)管理的缓存中的信息。我可以在自己的ListingResource类中手动创建它(有关如何执行的信息,请参见所述类中的注释掉的代码),但是当我将其设置为在请求范围内进行管理时则不能。
所有项目都是单独工作的,当我将它们放在一起时,它会崩溃并且抱怨存在未解决的依赖项。我提供了尝试构建时得到的堆栈跟踪,以及导致构建问题的类的一些相关代码片段。
是什么导致CDI中的问题?我唯一能想到的会导致此问题的原因是在查找相关bean时导致类型擦除导致的问题,但是我在代码中散布了泛型,到目前为止还没有问题。
如果有人希望看到完整的代码,则将实际代码在当前状态下推送到GitHub fork。
org.eclipsefoundation.marketplace.resource.ListingResource
@Path("/listings")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@RequestScoped
public class ListingResource {
private static final Logger LOGGER = LoggerFactory.getLogger(ListingResource.class);
@Inject
MongoDao dao;
@Inject
CachingService<List<Listing>> cachingService;
@Inject
RequestWrapper params;
@Inject
DtoFilter<Listing> dtoFilter;
@Inject
MongoQuery<Listing> q;
/**
* Endpoint for /listing/ to retrieve all listings from the database along with
* the given query string parameters.
*
* @param listingId int version of the listing ID
* @return response for the browser
*/
@GET
public Response select() {
//MongoQuery<Listing> q = new MongoQuery<>(params, dtoFilter);
...
org.eclipsefoundation.marketplace.model.MongoQuery
@RequestScoped
public class MongoQuery<T> {
private static final Logger LOGGER = LoggerFactory.getLogger(MongoQuery.class);
@Inject
RequestWrapper wrapper;
@Inject
DtoFilter<T> dtoFilter;
private Bson filter;
private Bson sort;
// flag that indicates that aggregate should be used as filter
private boolean useAggregate = false;
...
堆栈跟踪:
[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type org.eclipsefoundation.marketplace.model.MongoQuery<org.eclipsefoundation.marketplace.dto.Listing> and qualifiers [@Default]
- java member: org.eclipsefoundation.marketplace.resource.ListingResource#q
- declared on CLASS bean [types=[org.eclipsefoundation.marketplace.resource.ListingResource, java.lang.Object], qualifiers=[@Default, @Any], target=org.eclipsefoundation.marketplace.resource.ListingResource]
at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:835)
at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:214)
at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:106)
at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:249)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.quarkus.deployment.ExtensionLoader$1.execute(ExtensionLoader.java:768)
at io.quarkus.builder.BuildContext.run(BuildContext.java:415)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2011)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1535)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1426)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:479)```