2014-02-27 4 views
0

이미 웹에 StackOverflow 관련 질문이나 블로그 항목 등이 많이 있지만, 아래에 설명 된 문제에 대한 해결책을 찾을 수는 없습니다.JBoss 5의 JAX-RS 리소스 내에서 EJB 삽입하기

이 질문 (Injecting EJB within JAX-RS resource on JBoss7)과 유사하게 EJB 인스턴스를 JAX-RS 클래스에 삽입하고 싶습니다. 저는 JBoss 5, JBoss 7, WildFly 8을 사용했습니다. 나는 전혀 주입하지 않습니다 (필드가 null 임). 또는 서버가 배치하지 않습니다 (모든 종류의 주석을 결합하려고하자마자). @Stateless을 JAX-RS에 추가하면 응용 프로그램 서버가 두 클래스를 모두 Bean으로 인식합니다. 그러나 주사는 일어나지 않습니다.

EJB를 REST 애플리케이션에 삽입 할 수있는 방법이 있습니까? 위에 링크 된 질문에 포함 된 정보 이외에 어떤 정보가 도움이 될 수 있습니까?

편집 : Glassfish 4.0에서 작동하고 (JBoss 5에서) 작동하지 않는 코드를 보여주는 Github 프로젝트를 만들었습니다.

https://github.com/C-Otto/beantest

  • 은 글래스 피시 4.0 사용하여 작동 4bf2f3d23f49d106a435f068ed9b30701bbedc9d 커밋합니다.
  • 커밋 50d137674e55e1ceb512fe0029b9555ff7c2ec21은 작동하지 않는 Jersey 1.8을 사용합니다.
  • 커밋 86004b7fb6263d66bda7dd302f2d2a714ff3b939 도 Jersey 2.6을 사용합니다.이 역시 작동하지 않습니다.

EDIT2 : 내가 글래스 피시 4.0 JBoss의 5에 노력 코드의 실행 을 제공합니다

Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Ref<ContainerRequest>] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject org.glassfish.jersey.server.internal.routing.UriRoutingContext(Ref<ContainerRequest>, ProcessingProviders)] 
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Ref<ContainerRequest>] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject org.glassfish.jersey.server.internal.routing.UriRoutingContext(Ref<ContainerRequest>, ProcessingProviders)] 
    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:403) 

EDIT3을 : 결정적인 정보는 내가 보스 5

에서 작동하는 솔루션을 원하는 것일 수도
+0

관련을 게시하시기 바랍니다 : 당신이 (당신이 짐작) 자바 EE 6 이상을 사용하는 경우 JNDI 조회 현재 문제없이 당신을 위해 노력하고, 경우, 다음을 수행 할 수 있습니다 암호. – Camilo

+0

나는이 사람이 꽤 잘 설명했다고 생각했다. http://stackoverflow.com/questions/3027834/inject-a-ejb-into-jax-rs-restfull-service – ZeusSelerim

+0

실제로 방법이 있으며 기본적으로 그것을 성취하기 위해 특별한 일을하십시오. JAX-RS 리소스는 EJB 자체 여야하며 충분합니다. 문제는 코드의 어딘가에 있어야합니다. 그래서 카밀로와 동의 할 것입니다. 코드를보고 문제를 이해하는 데 도움이 될 수 있습니다. – jjd

답변

2

JAX-RS 리소스도 EJB로 만들고 (@Stateless), @EJB 또는 @Resource을 삽입하고 싶지 않은 경우 JNDI 조회를 사용할 수 있습니다 ("ServiceLocator"클래스를 작성하는 경향이 있습니다. 해당 클래스를 통해 서비스를 얻습니다.

좋은 자원이 주제에 대해 읽기 :

https://docs.jboss.org/author/display/AS71/Remote+EJB+invocations+via+JNDI+-+EJB+client+API+or+remote-naming+project

샘플 코드 :

이 당 자체 "주입"되지
try { 
    // 1. Retreive the Home Interface using a JNDI Lookup 
    // Retrieve the initial context for JNDI.  // No properties needed when local 
     Context context = new InitialContext(); 

     // Retrieve the home interface using a JNDI lookup using 
     // the java:comp/env bean environment variable  // specified in web.xml 
     helloHome = (HelloLocalHome) context.lookup("java:comp/env/ejb/HelloBean"); 

    //2. Narrow the returned object to be an HelloHome object.  // Since the client is local, cast it to the correct object type. 
    //3. Create the local Hello bean instance, return the reference 
     hello = (HelloLocal)helloHome.create(); 

    } catch(NamingException e) { 

    } catch(CreateException e) { 

    } 

하지만, 사용하지 않는 " new "를 사용하면 응용 프로그램 서버에서 관리되는 인스턴스를 제공 할 수 있습니다.

나는 이것이 유용하고 이미 알고있는 것을 말하지 않을 것이라고 희망한다!

편집 :

이 훌륭한 예입니다 https://docs.jboss.org/author/display/AS72/EJB+invocations+from+a+remote+client+using+JNDI

편집 2 : 당신은 당신의 코멘트에 명시된 바와 같이
, 당신은 주석을 통해 주입하고 싶습니다.

@EJB(lookup = "jndi-lookup-string-here") 
private RemoteInterface bean; 
+0

슬프게도, 이것이 우리의 현재 접근 방식입니다. 내가 _do_ 주석을 사용하고 @Stateless를 추가하거나 비슷한 것이 도움이되지 않길 원합니다. –

+0

@ C-Otto에 대한 답변을 업데이트했습니다. –