javajava-8websphereejbejb-3.1

EJB3 Websphere Custom JNDI Binding


I have an application which I am migrating an application(EJB Application to be specific) to EJB 3.1 from EJB 2.1.

Now, I want a custom JNDI mapping for a Stateless bean. I had set the mappingName with the Stateless Annotation, but it only sets the mapped-name XML Tag in the ejb-jar_merged.xml file.

Now, I want to set the following simple-binding-name programatically, probably via using the EJB3.1 Annotations. Is that possible to do so?

I except the following, ibm-ejb-jar-bnd.xml to look this way(Potentially without creating this file manually).

<session name="SomeEJBBean" simple-binding-name="ejb/org.abc.ejbclient.SomeEJBBean"/>

Any help is greatly appreciated.


Solution

  • For direct EJB lookups, the only way to configure a custom JNDI name for an EJB in WebSphere is through the use of the ibm-ejb-jar-bnd.xml file. There is no mechanism for generating this file from annotations, nor is there a way to provide a custom JNDI name with an annotation.

    To improve the portability of EJB applications, the EJB 3.1 specification added a well defined JNDI name for all EJBs in java:global, java:app, and java:module, but did not provide a way to customize those binding names.

    The EJB specification also introduced the mappedName attribute of the @Stateless and @Stateful annotations. However, this attribute has undefined behavior and is not required, so WebSphere chose not to provide an implementation for this attribute as it would not be portable.

    Another option to consider is that an application may provide a "custom" JNDI name for an EJB through the use of an EJB reference (i.e., <ejb-ref> or <ejb-local-ref> in ejb-jar.xml or @EJB annotation).

    Consider the following example:

    @Stateless
    @Remote(ClientRemote.class)
    @EJB(name="java:global/env/ejb/ClientBeanRef", beanInterface=ClientRemote.class, beanName="ClientBean")
    public class ClientBean
    
    

    The specification defined JNDI name for the ClientBean would be something like:

    java:global/TestApp/TestEJBModule/ClientBean!org.test.ClientRemote
    

    So, the bean could be looked up directly using this name, or, if using the EJB reference name, it would just be:

    java:global/env/ejb/ClientBeanRef
    

    Or any other name specified on the @EJB annotation in the java:global, java:app, or java:module naming contexts.

    Note that bindings provided for an EJB reference will not be visible from a thin client, so this may not be an option if that is important for your application.

    Full details about other EJB binding related options in WebSphere may be found here: