我希望在一个由子资源定位器定义并提供的子资源中注入一个业务服务bean。
以下是一些示例代码:
A root resource
@RequestScoped @Path("service") public class MyResource { @Context ResourceContext resourceContext; // Sub resource locator @Path("subservice") public MySubResource locateToSubResource () { // I don't want to create it myself. return resourceContext.getResource(MySubResource.class); } }
The corresponding sub resource
@RequestScoped public class MySubResource { // Note that businessBean itself consists of // multiple ejbs that also need to be injected so that it can do its job! @Inject private BusinessBean businessBean; @GET @Produces(MediaType.TEXT_PLAIN) public String get () { return businessBean.doStuff(); } }
@RequestScoped
?如果没有它,也可以工作,我认为你不需要将CDI bean注入到另一个bean中,但它也适用于JAX-RS资源类(例如)吗? - Hein Blöd