Hi guys,
I posted on here a couple of days ago about problems I was having deploying EJB3.0 on teh Sun WebApp 9.0.
Whilst I've mnaged to deploy my
EJB & Client (SimpleServlet) as seperate modules (web.war & ejb.jar) I am still
having trouble getting the
Servlet to connect with the EJB...
I have chosen the XML deployment descriptor route over Annotation because it seems easier for changing
(especially during development) also I'm not keen on having this sort of info in the actual code.
Below are (what I think) are the relivent files and code bits, could someone please help me understand why the
Servlet is throwing the 'NameNotFoundException' Exception when connecting to the SampleModel bean.
Any help would be Cheers
KS
SampleServlet
-------------
try {
InitialContext cxt = new InitialContext();
SampleRemote remote = (SampleRemote)cxt.lookup("java:comp/env/ejb/SampleModel");
System.out.println("Name: "+remote.getName());
} catch (NamingException NEx) {
System.out.println("Naming Exception: "+NEx);
}
web.xml
-------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet>
<servlet-name>SampleServlet</servlet-name>
<servlet-class>com.myclient.servlets.SampleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SampleServlet</servlet-name>
<url-pattern>/web/SampleServlet</url-pattern>
</servlet-mapping>
<ejb-ref>
<ejb-ref-name>ejb/samplemodel</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.myproject.sample1.SampleLocal</home>
<remote>com.myproject.sample1.SampleLocal</remote>
<ejb-link>SampleBean</ejb-link>
</ejb-ref>
</web-app>
ejb-jar.xml
-----------
<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee" version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"> <description>
Sample
</description>
<enterprise-beans>
<session>
<description>
Sample Bean for
testing </description>
<display-name>
SampleBean
</display-name>
<ejb-name>SampleModel</ejb-name>
<business-local>com.myproject.sample1.SampleLocal</business-local>
<business-remote>com.myproject.sample1.SampleRemote</business-remote>
<ejb-class>com.myproject.sample1.SampleModel</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
sun-ejb-jar.xml
---------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 9.0 EJB 3.0//EN'
'http://www.sun.com/software/dtd/appserver/sun-ejb-jar_3_0-0.dtd'>
<sun-ejb-jar>
<display-name>Sample</display-name>
<enterprise-beans>
<unique-id>1</unique-id>
<ejb>
<ejb-name>SampleModel</ejb-name>
<jndi-name>samplemodel</jndi-name>
</ejb>
</enterprise-beans>
</sun-ejb-jar>
</xml>
server.log
----------
[#|2007-10-10T11:37:38.400+0100|INFO|sun-appserver-pe9.0|javax.enterprise.system.stream.out|_ThreadID=11;_ThreadName=httpWorkerThread-8080-0;|
Naming Exception: javax.naming.NameNotFoundException: No object bound to name
java:comp/env/ejb/SampleModel|#]