[jboss-user] [EJB 3.0] - Accessing stateless EJB3 bean from a WAR

michael.litherland do-not-reply at jboss.com
Mon Jul 21 15:45:21 EDT 2008


Hi,

I've searched and read and tried a hundred things, but I'm pulling my hair out on this one.  I have a desire to deploy similar, but subtly different EJB projects on a JBoss 4.2.2 application server, then allow my WARs to call those EJB methods using the remote interface.  This way for a new customer I deploy a new EJB and the tweaks to the WAR are relatively minor to allow access to the additional EJB project.  This seems like it should be straightforward, but I can't overcome a few problems.  Here's part of my stateless bean:


  | @Stateless
  | @RemoteBindings({@RemoteBinding(jndiBinding="custom/remote/MyBean")})
  | public class MyBean implements MyBean {
  |     @PersistenceContext(unitName = "S1-ejbPU")
  |     private EntityManager em;
  |     public List<SomeOtherBean> getBeans() {
  | ...
  | 

My understanding is I need to create an ejb-ref in my web.xml, jboss-web.xml and finally call that from my code (which is a JSF managed bean in this case.  First the jboss-web.xml:


  | <jboss-web>
  | ...
  |     <ejb-ref>
  |         <ejb-ref-name>ejb/MyBean</ejb-ref-name>
  |         <jndi-name>custom/remote/MyBean</jndi-name>
  |         <!-- also tried this:
  |         <jndi-name>jnp://localhost:1099/custom/remote/MyBean</jndi-name>
  |         -->
  |     </ejb-ref>
  | </jboss-web>
  | 

The web.xml:


  | <web-app ....
  | 
  |     <ejb-ref>
  |         <ejb-ref-name>ejb/MyBean</ejb-ref-name>
  |         <ejb-ref-type>Session</ejb-ref-type>
  |         <home/>
  |         <remote>MyBean</remote>
  |     </ejb-ref>
  | </web-app>
  | 

Lastly in the code itself:


  |     @EJB(name="java:comp/env/ejb/MyBean")
  |     private MyBeanRemote mbr;
  | 

I've tried many variations, but it's not clear to me, even after reading documentation, what all of the various pieces actually do within this processes, nor what I should be calling what.  I'd love to see a simplified howto for setting up something like what I desire or suggestions for "better ways" to attempt this.

Thanks,
Mike

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4165737#4165737

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4165737



More information about the jboss-user mailing list