I was testing an EJB 2.x application. I created 2 module separately:
EJB module: contains a simple stateless session bean
Web module: contains a single servlet page to lookup EJB module.
I was using Jboss 4.2.3
.
First, I deployed the EJB module and the deployment went well. Second, I deployed the web module and the deployment went well.
Then I used the following code to look up the EJB module:
Context c = new InitialContext();
Object o = c.lookup("HelloJNDI"); // Line 1
HelloLocalHome rv = (HelloLocalHome) o; // Line 2
HelloLocal local = rv.create();
The lookup went well (Line 1
), but Line 2
produced a class cast exception.
Then I test the above code in 2 scenarios:
I packaged the EJB and the Web module into a single
EAR module
. Then, deployed thisEAR
module inJBoss 4.2.3
, and the lookup code above worked like a charm.I tried to use
JBoss 5
, and even deployed the EJB module and the Web module separately, the lookup code above worked great.
So, why when I deployed the 2 modules separately in JBoss 4, things did not work out? I use local JNDI lookup only because the 2 modules were deployed in the same container. Was I missing something or this is a flaw in JBoss 4?