문제 설명
주입을 통해 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.xml
file 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 @Inject
in the final destination.)
(by Jeenson Ephraim、Robby Cornelissen、LightGuard、weaselflink)