我有一个简单的 Quarkus 资源:
@Path("/rosters")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class RosterResource {
private final RosterService rosterService;
public RosterResource(RosterService rosterService){
this.rosterService = rosterService;
}
@GET
@Path("/{rosterId}")
public Response getRoster(@PathParam("rosterId")Long rosterId){
return Response.ok(rosterService.getRosterById(rosterId)).build();
}
}
我正在尝试将RosterService实例注入我的资源中,但我得到了一个javax.enterprise.inject.UnsatisfiedResolutionException. 但是,如果我在@ApplicationScoped上使用注释RosterService,那么一切正常。有没有办法在我的资源中注入RosterService类而不使用注释?换句话说,有没有办法让RosterServiceQuarkus 容器可以发现而不直接注释类?
编辑:查看CDI 文档,您似乎可以使用带有@BuildStep注释的方法手动注册 bean。但是,我不清楚哪个类应该包含带注释的方法)
另一种选择是使用Jandex 索引