javaejbwebsphereejb-3.1ejb-2.x

EJB 2.1 to EJB 3.1 Migration - Session EJB with name not found


I am migrating Ejb 2.1 to Ejb 3.1. I changed Java Version from 1.6 to 1.8, and Ejb Version from 2.1 to 3.1. Once I made the changes, I am getting problems in the ibm-ejb-jar-bnd.xml and ibm-ejb-jar-ext.xml files. I am getting these messages:

1: Session EJB with name 'abcEJB' not found
2: Resource reference with name 'ResourceRef_xyz' not found for this EJB or interceptor

Am I missing anything?

enter image description here


enter image description here


Solution

  • I have migrated from EJB 2.1 to EJB 3.1 couple of years back and I recall facing the same issues and error you are facing.

    Although I don't remember the exact action that fixed the issue nor other issues I faced along the way, but I will tell you what I did to fix ALL issues, including this one.

    Note: It's not an easy task to migrate, but following these next steps as described will save you lots of hassle later on.

    1. Annotate session beans and interfaces with proper annotations: In my case I had remote interfaces for EJB 2.1 beans. Since I did not need an actual remote interface in my application, I switched them into local interfaces.
    2. Empty ibm-ejb-jar-bnd.xml and ibm-ejb-jar-ext.xml enter image description here
    3. Change clients to lookup either using DI, JNDI name. In my case I used JNDI lookup.

    Now the code should look like this:

    Session Bean interface:

    @Local
    public interface MySessionInterface {
        // TODO :: declare business methods
    }
    

    Session bean implementation:

    @stateless
    public interface MySessionBeanImpl implements MySessionInterface {
        // TODO :: implement business methods
    }
    

    Service Locator to lookup EJBs using JNDI:

    public class ServiceLocator {
        public final <T> T getLocalSession(Class<T> _class) throws NamingException {
            return (T) new InitialContext().lookup("ejblocal:" + _class.getName());
        }
    }
    

    Client:

    public class SessionClient {
         public void performOperation() {
             try {
                MySessionInterface session = ServiceLocator.getLocalSession(MySessionInterface.class);
                // TODO :: perform business logic here
            } catch (NamingException e) {
                 // TODO :: handle exception
            }
        }
    }
    

    Of course service locator can have the following improvements but I removed them for brevity:

    Hope you find it useful.