EJB3 Stateless Session Bean not bound error
rnotani Jun 10, 2006 1:25 PMHi,
I have a really simple EJB3 sample adapted from the Trailblazer application.
I have a Servlet (ExampleServlet.java) that does a lookup of a Stateless Session Bean (TestServiceImpl.java).
The lookup code is
Context jndiContext = new jndiContext();
TestService ts = (TestService)jndiContext.lookup("TestServiceImpl");
When I do this I get a javax.naming.NameNotFoundException: TestServiceImpl not found.
When I print out the JNDI context from the Servlet, I do not see TestServiceImpl or anything related to my beans.
My application is packaged as a single ear file (example.ear) which contains
application.xml
jboss-app.xml
app.jar
....TestService.java
.....TestServiceImpl.java
.....Persistence.xml
web.war
.....ExampleServlet.class
......MyJSP.jsp
......web.xml
My TestServiceImpl class looks like
@Stateless
@Local(TestService.class)
@LocalBinding(jndiBinding="TestServiceImpl")
public class TestServiceImpl implements TestService
public int add(int i, int j)
{ return i+j;
}
}
The @Local and at @LocalBinding are recent additions. Initially I
did not have them and tried the following context lookups to
no avail.
TestService ts = (TestService)jndiContext.lookup("example/TestServiceImpl/local");
Note: my ear file is example.ear
TestService ts = (TestService)jndiContext.lookup("TestServiceImpl/local");
When I deploy the ear file (example.ear) into JBoss (I am using JBoss 4.0.4) I get no errors and the Servlet and JSP invoke fine.
My persistence.xml file is:
<persistence>
....<persistence-unit name="example">
..........<jta-data-source>java:/DefaultDS</jta-data-source>
......</persistence-unit>
</persistence>
My application.xml file is: (ignore the dots in "module" and "web" below...
I needed those to prevent this forum software from getting confused)
.... usual XML headers ....
<display-name>Example Application</display-name>
<module.>
.....<ejb>app.jar</ejb>
</module.>
<module.>
......<web.>
.............<web-uri>web.war</web-uri>
..............<context-root>Example</context-root>
......</web.>
</module.>
My jboss-app.xml file is
... usual XML headers...
<jboss-app>
....<loader-repository>
...........example:app=ejb3
.....</loader-repository>
</jboss-app>
My jboss-web.xml file is
.... usual XML headers
<jboss-web>
....<security-domain>java:/jaas/other</security-domain>
</jboss-web>
My web.xml file is
.... usual XML headers
<web-app>
......<display-name>Example</display-name>
......<servlet>
............<servlet-name>ExampleServlet</servlet-name>
...........<servlet-class>web.other_servlets.ExampleServlet</servlet-name>
......</servlet>
.......<servlet-mapping>
............<servlet-name>ExampleServlet</servlet-name>
............<url-pattern>/do/*</url-pattern>
.......<servlet-mapping>
</web-app>
I have been struggling over this for the past 2 days, so any help will be greatly appreciated..
My current hypotheses are
1) Some configuration error that I cannot pick up
2) The stateless session bean (ExampleServiceImpl) is being
registered in some naming context the the Servlet does not
have access to.
3) The stateless session bean is not getting registered at all (despite
no errors on deploy).
thanks,
Ranjit