我有一个实用程序类:
@RequestScoped
public class StatsServicesDataImpl {
@Qualifier
@Retention(RUNTIME)
@Target({ METHOD, PARAMETER })
public @interface Lines {
}
@Qualifier
@Retention(RUNTIME)
@Target({ METHOD, PARAMETER })
public @interface Versions {
}
public StatsServicesDataImpl() {
}
@Produces
@Versions
@Transactional(TxType.REQUIRES_NEW)
public String getVersionsAsJsonString() {
log.debug("CDI calls getVersionsAsJsonString");
...
return json.toString();
}
@Produces
@Lines
@Transactional(TxType.REQUIRES_NEW)
public String getLinesAsJsonString() {
log.debug("CDI calls getLinesAsJsonString");
...
return json.toString();
}
}
然后是一个JAX-RS类,带有:
@GET
@Path("/versions")
@Produces(MediaType.APPLICATION_JSON)
@Inject
public Response getVersions(@Versions String versions) {
log.debug("Endpoint versions :" + versions);
return Response.ok(versions).build();
}
@GET
@Path("/lines")
@Produces(MediaType.APPLICATION_JSON)
@Inject
public Response getLines(@Lines String lines) {
log.debug("Endpoint lines :" + lines);
return Response.ok(lines).build();
}
它不能按预期工作:( 我希望当我调用URL行时,CDI获得行(@Inject和@Lines)并拥有JSON。 但是当我拨打电话(http://...../lines)时,我得到了:
CDI calls getLinesAsJsonString
Endpoint lines :{"lignes":[{"id":97,"idu":1,"nom":"01"},{"id":98,"idu":2,"nom":"02"},{"id":99,"idu":3,"nom":"03"},{"id":100,"idu":4,"nom":"04"},{"id":101,"idu":5,"nom":"05"}]}
CDI calls getVersionsAsJsonString
Endpoint versions :{"versions":[{"id":71,"vdhId":19,"vdrId":18,"vdpId":18,"vdhNom":"Importé le 2017-08-10 Septembre 2017 V1","vdhDateExp":"Sep 1, 2017 12:00:00 AM","jexDateDeb":"Sep 1, 2017 12:00:00 AM","jexDateFin":"Aug 10, 2018 12:00:00 AM","downloadedDate":"mai 1, 2018"}]}
Endpoint lines :
当我调用版本时:
CDI calls getLinesAsJsonString
Endpoint lines :{"lignes":[{"id":97,"idu":1,"nom":"01"},{"id":98,"idu":2,"nom":"02"},{"id":99,"idu":3,"nom":"03"},{"id":100,"idu":4,"nom":"04"},{"id":101,"idu":5,"nom":"05"}]}
CDI calls getVersionsAsJsonString
Endpoint versions :{"versions":[{"id":71,"vdhId":19,"vdrId":18,"vdpId":18,"vdhNom":"Importé le 2017-08-10 Septembre 2017 V1","vdhDateExp":"Sep 1, 2017 12:00:00 AM","jexDateDeb":"Sep 1, 2017 12:00:00 AM","jexDateFin":"Aug 10, 2018 12:00:00 AM","downloadedDate":"mai 1, 2018"}]}
Endpoint versions :
相同的结果:(好像两个生产者方法都被称为...
有什么想法如何结合JAX-RS和CDI,以便我可以在Rest-request的响应中注入请求的结果(由CDI生成)?