Discussion:
[jboss-user] [EJB3] - Access EJB from different WAR in JBoss AS via injection
charlie7
2013-05-13 16:18:06 UTC
Permalink
charlie7 [https://community.jboss.org/people/charlie7] created the discussion

"Access EJB from different WAR in JBoss AS via injection"

To view the discussion, visit: https://community.jboss.org/message/817451#817451

--------------------------------------------------------------
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 http://www.verborgh.be/articles/2010/01/06/porting-the-viewscoped-jsf-annotation-to-cdi 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
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/817451#817451]

Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
Robby Cornelissen
2013-05-14 02:21:18 UTC
Permalink
Robby Cornelissen [https://community.jboss.org/people/robby.cornelissen] created the discussion

"Re: Access EJB from different WAR in JBoss AS via injection"

To view the discussion, visit: https://community.jboss.org/message/817508#817508

--------------------------------------------------------------
I got it to work using the following approach:

1. Define EJBs as resources using the @Produces annotation:

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




# Inject the EJB resources in your bean using the @Inject annotation: {code}// ...

@Inject
private WhateverService whateverService;

// ...
{code}

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

Reply to this message by going to Community
[https://community.jboss.org/message/817508#817508]

Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
charlie7
2013-05-14 10:28:54 UTC
Permalink
charlie7 [https://community.jboss.org/people/charlie7] created the discussion

"Re: Access EJB from different WAR in JBoss AS via injection"

To view the discussion, visit: https://community.jboss.org/message/817599#817599

--------------------------------------------------------------
That worked . Thansk for helping out
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/817599#817599]

Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
Loading...