English 中文(简体)
Injecting EJB within JAX-RS resources on JBoss7
原标题:Injecting EJB within JAX-RS resource on JBoss7

我很想知道为什么Ejb注入日本宇宙航空研究开发机构-RS资源(JBoss7的RestEasy)不奏效。 欧洲复兴开发银行不是战争的一部分,而是其自身的EJB jar,但我认为这不是问题。 I m 被迫做“工作环绕”,这并不好。 我一无所事,或真的不支持把EJB像这样说? 下面的例例并不与JBos公司合作,而是与玻璃鱼合作(当时,我对JBoss的申请进行了管理)。

Path("x")
@RequestScoped
public class UserResource {

    @Inject // CDI not working too
    private Service service1;
    @EJB
    private Service service2;

    private Service service3;


    @GET
    @Path("y")
    public Response authenticate(@Context HttpHeaders headers) {
         System.out.println("null == " + service1);
         System.out.println("null == " + service2);

         service3 = annoyingLookup(Service.class);
         System.out.println("null != " + service3);
    }

    private <T> T annoyingLookup(Class<T> clazz) {
       ...
       ctx.lookup("java:app/module/" + classzz.getSimpleName());
    }
最佳回答

The following is working for me.

REST 2. 便利根基:

package com.foo.rest;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/rest")
public class RestServiceLocator extends Application {

}

STLS bean:

package com.foo.rest;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;

@Path("/foo")
@Stateless
@LocalBean //Note: @Local(FooResource.class) does not let RESTEasy to load EJB!
public class FooResourceBean implements FooResource {

    @EJB 
    private FooResourceBean h; // Works!

    /**
     * http://localhost:8080/webapp/rest/foo/baa
     *  
     */
    @GET
    @Path("/baa")
    @Produces("application/json")
    @Override
    public Response baa() {

        String json = "{ "baa" : [ " +
                      "             { "icon":"source1.png" , "description":"Source 1" }, " +
                      "             { "icon":"source2.png" , "description":"Source 2" }, " +
                      "             { "icon":"source3.png" , "description":"Source 3" } " +
                      "          ]}";";

        return Response.ok(json).build();
    }

}
问题回答

增 编

@Stateless

D. 获取日本宇宙航空研究开发机构资源

@Path("/")
@Stateless
public class MainMain
{    

    @EJB(mappedName = "java:global/optima-wsi/OptimaConfigurator!com.sistemaits.optima.configurator.IOptimaConfigurator")
    IOptimaConfigurator configurator;

    ---
}




相关问题
Implementing SSO with SAML and JBoss

I want to implement SSO with SAML tokens in JBossAS. The scenario is as follows. I have 2 applications app1 and app2 running on 2 JBoss instances. Login into app1 and enter username / password ...

How do you efficiently repeat an action every x minutes?

I have an application that runs in JBoss. I have an incoming web service request that will update an ArrayList. I want to poll this list from another class every 60 seconds. What would be the most ...

jsp:how to hide folder structure of website from users?

how to hide folder structure of website from users. i have developed a website on jave platform (jsp). website is deployed on jboss. suppose my website s home page url is dummy.com/dummyFolder/...

JBoss Web Services Behind IIS Through HTTPs

This is a tangled web that s woven, I suppose, but it really shouldn t be all that hard. Let me see if I can paint the picture: I have written a web service, starting with a WSDL, which is to run in ...

Flex: image scale stopped working after deploy to server

I have some code to scale an image s width according to its height after the image is being loaded. It works fine on my development PC if I point to the wrapper html using local file system path. ...

How in jboss write traces to separate trace file

How in JBoss to write traces to separate file? I would like to see traces about org.hibernate.SQL and org.hibernate.type in separate trace file. I added next appender and categories to jboss-log4j....

热门标签