jndi binding for local and remote stateless bean

19,566
  1. If you use EJB3.0 you may use @Localbinding / @Remotebinding in JBoss. If you use EJB 3.1, the JNDI bindings are standardized (called portable global JNDI name).

  2. name attribute of the @Stateless/@Stateful annotation defines the name of the bean. It's default is the unqualified class name.

  3. mappedName attribute of the @Stateless/@Stateful annotation is used to map the bean to a JNDI name. If you provide this attribute, you need to provide the mappedName attribute of the @EJB annotation in order to reference the bean. In terms of mapping:

    @Stateless(name="Bar")       => @EJB(beanName="Bar")
    @Stateless(mappedName="Foo") => @EJB(mappedName="Foo")
    

In your example, try to use:

public class RoutingServiceBean {
    ...
    @EJB(mappedName=IRemoteInterface.JNDI_NAME)
    public ILocalInterface iLocalInterface;
}
Share:
19,566
R Vive L OL
Author by

R Vive L OL

Updated on June 29, 2022

Comments

  • R Vive L OL
    R Vive L OL almost 2 years

    I'm trying to implements an EJB3 stateless with a remote and local interfaces the problem is the local one is called in an other remote EJB with the annotation @EJB but it returns null or ClassCastException (java.lang.ClassCastException: com.sun.proxy.$Proxy58 cannot be cast).

    To perform the lookup on the server to get the local stateless I have to put 2 JNDI names for the stateless else it gives me the remote one.

    @Stateless(mappedName=IRemoteInterface.JNDI_NAME, description="...")
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    @Interceptors({GenericInvocationHandler.class})
    @Remote(IRemoteInterface.class)
    @Local(ILocalInterface.class)
    public class MystatelessBean extends AbstractBasicBean implements 
        IRemoteInterface, ILocalInterface {
       ...
    }
    
    @Stateless(mappedName=IRouting.JNDI_NAME, description="gives access to other services")
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    @Interceptors({GenericInvocationHandler.class})
    @Remote(IRouting.class)
    public class RoutingServiceBean extends AbstractBasicBean implements IRouting {
    
        @EJB
        public ILocalInterface iLocalInterface;
    
    }
    

    Actually, when I use @EJB I get NPE and when I use @EJB(beanName=IRemoteInterface.JNDI_NAME) I get ClassCastException which is right JNDI name of the remote interface.

    I m looking for something like @LocalBinding and @RemoteBinding in JBoss.

    Maybe I'm missing something?

  • R Vive L OL
    R Vive L OL almost 11 years
    Hello Simon, thanks for your answer, but the problem is that you can't cast a remote to a local, what i want is to use both local and remote beans, i think that applications servers are not enaught intelligent to use the local bean if the call is in the same JVM and a remote otherwise. I found a bad solution is to not fix the name of the beans, and reconver them from the jndi of the AS and then use these names to call remote or local bean.
  • António Ribeiro
    António Ribeiro about 8 years
    Since JBoss AS 7 (or enterprise JBoss EAP 6), the binding of EJBs to custom JNDI names isn't allowed anymore either by annotations or XML configuration. Therefore, your reference to both @LocalBinding and @RemoteBinding should be revised.