주입을 통해 JBoss AS의 다른 WAR에서 EJB에 액세스 (Access EJB from different WAR in JBoss AS via injection)


문제 설명

주입을 통해 JBoss AS의 다른 WAR에서 EJB에 액세스 (Access EJB from different WAR in JBoss AS via injection)

My Project structure is as follows

JBoss AS 7.1.3.Final‑redhat‑4

A war VWeb.war which contains an EJB , when VWeb is deployed I get the following

 java:global/VWeb/QServiceImpl!com.vi.qciapi.QService
java:app/VWeb/QServiceImpl!com.vi.qciapi.QService
java:module/QServiceImpl!com.vi.qciapi.QService
java:global/VWeb/QServiceImpl
java:app/VWeb/QServiceImpl
java:module/QServiceImpl

I have got another war (ControlWeb‑portlet.war) which is a liferay project and I am trying to access the above EJB within a bean from ControlWeb‑portlet . The bean is @ViewScoped This has been done based on a link found here

I have tried all these combinations but nothing seems to work

@Inject
QService qService;

@EJB
QService qService;

@EJB(mappedName="java:global/VWeb/QServiceImpl!com.vi.qciapi.QService")
QService qService;

@EJB(beanInterface=QService.class)
QService qService;

@EJB(mappedName="java:global/VWeb/QServiceImpl!com.vi.qciapi.QService")
QService qService;

I kept an EJB in the same project ControlWeb‑portlet which is deployed as follows

java:global/ControlWeb‑portlet/CdiServiceImpl!com.clink.cdi.CdiServiceImpl
    java:app/ControlWeb‑portlet/CdiServiceImpl!com.clink.cdi.CdiServiceImpl
    java:module/CdiServiceImpl!com.clink.cdi.CdiServiceImpl
    java:global/ControlWeb‑portlet/CdiServiceImpl
    java:app/ControlWeb‑portlet/CdiServiceImpl
    java:module/CdiServiceImpl

and I am able to inject the EJB with

@EJB
CdiServiceImpl cdiServiceImpl;

Is there anything specific that I have to while accessing an EJB from a different WAR

Thanks in advance

Charlie


참조 솔루션

방법 1:

Apparently I answered this question on the JBoss forums a while ago. Since it was marked as the correct answer there, I thought I'd reproduce it here as well.


I got it to work using the following approach:

First, define EJBs as resources using the @Produces annotation:

public class Resources {
          @Produces
          @EJB(lookup = "java:global/.../WhateverService")
          private WhateverService whateverService;
}

Then, inject the EJB resources in your bean using the @Inject annotation:

// ...
@Inject
private WhateverService whateverService;
// ...

Works like a charm. I'm also using a similar CDI view scope approach.

방법 2:

If I'm understanding correctly, you should keep using @EJB for a remote bean.

방법 3:

One possible fix is to add a dependency to VWeb.war into the jboss‑deployment‑structure.xmlfile in the second war. Which would look like this:

<jboss‑deployment‑structure>
  <deployment>
    <dependencies>
      <module name="deployment.VWeb.war" />
    </dependencies>
  </deployment>
</jboss‑deployment‑structure>

If that doesn't work you could also try a workaround described here. (Create a @Stateless EJB in ControlWeb‑portlet.war which injects the required bean via @EJB and then exposes this via producer methods, which allow you to use @Injectin the final destination.)

(by Jeenson EphraimRobby CornelissenLightGuardweaselflink)

참조 문서

  1. Access EJB from different WAR in JBoss AS via injection (CC BY‑SA 3.0/4.0)

#jakarta-ee #cdi #jboss7.x #ejb-3.1 #java






관련 질문

주입을 통해 JBoss AS의 다른 WAR에서 EJB에 액세스 (Access EJB from different WAR in JBoss AS via injection)

데이터베이스 필드를 매일 확인하려면 어떻게 해야 합니까? 크론 작업? (How can I check database field every day?Cron job?)

Java ee netbeans에서 javadocs를 첨부하는 방법 (How to attach javadocs in java ee netbeans)

날짜 차이 제한 최대 절전 모드 (Date difference in days Restriction Hibernate)

Wildfly 8.2.1에서 EJB 2.1에 액세스할 때 ClassCastException이 발생하는 이유는 무엇입니까? (Why I am getting ClassCastException when accessing EJB 2.1 in Wildfly 8.2.1?)

WebLogic Application Server(10.3.6)가 큰 크기의 이어 파일 배포, 중요한 CSRF로 실패함 (WebLogic Application Server (10.3.6) fails with Large sized ear file deployment, critical CSRF)

개체 배열을 설정하는 동안 FindBug 오류 '변경 가능한 개체에 대한 참조를 통합하여 내부 표현을 노출할 수 있음'을 수정하는 방법은 무엇입니까? (How to Fix FindBug error 'May expose internal representation by incorporating reference to mutable object' while setting Array of Objects?)

Stateless EJB가 역직렬화될 때 @Resource 주석이 적용됩니까? (Is the @Resource annotation applied when a Stateless EJB is deserialized?)

Eclipse 및 웹 프로젝트 가져오기, 서버에서 실행 누락! (Eclipse and Web Project import, run on Server missing!)

Spring 다중 모듈 프로젝트를 설정하는 방법은 무엇입니까? (How to setup a Spring multimodule project?)

JBoss 5.1의 Java EE 빈에서 빈 EntityManager (Empty EntityManager in Java EE bean on JBoss 5.1)

사용자가 찾을 수 없는 페이지를 요청했는지 감지하는 필터를 만드는 방법은 무엇입니까? (How to make a filter to detect if the user requested a page that is not found?)







코멘트