依赖注入 – 泽西岛:如何将EJB注入子资源?
发布时间:2020-12-14 04:59:08 所属栏目:百科 来源:网络整理
导读:我想在子资源中注入一个商务服务bean,该子资源在专用类中定义并由子资源定位器传递. 一些示例代码: 根资源 @RequestScoped@Path("service")public class MyResource { @Context ResourceContext resourceContext; // Sub resource locator @Path("subservic
我想在子资源中注入一个商务服务bean,该子资源在专用类中定义并由子资源定位器传递.
一些示例代码: >根资源 @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); } } >相应的子资源 @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(); } } Jersey不会让CDI调用依赖项…请注意,资源是托管对象.否则甚至不可能在根资源中注入一个bean(here I’m pushing my other questions’ view count to get more opinions (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |