I have a simple EJBJar ,Say myHelloEjb.jar
Having 1.HelloBean.java
2.HelloObject.java
3.HelloHome.java
I put the the jar in Tomcat's lib folder and in Tomcat's examples directory I have a jsp openejb.jsp.Code Snippet :
InitialContext initCtx = new InitialContext();
Object object = initCtx.lookup("java:comp/env/ejb/Hello");
HelloHome helloHome = (HelloHome)
javax.rmi.PortableRemoteObject.narrow(object, HelloHome.class);
HelloObject bean = helloHome.create();
And added web.xml in examples web-inf folder as :
<ejb-local-ref>
<ejb-ref-name>ejb/Hello</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>org.acme.HelloHome</local-home>
<local>org.acme.HelloHome</local>
</ejb-local-ref>
When i am calling http://localhost:8080/examples/openejb.jsp
getting :
Aug 1, 2011 6:05:08 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.naming.NamingException: ejb-ref deploymentId is null
at org.apache.openejb.tomcat.common.EjbFactory.buildJndiName(EjbFactory.java:64)
at org.apache.openejb.tomcat.common.AbstractObjectFactory.getObjectInstance(AbstractObjectFactory.java:43)
at org.apache.openejb.tomcat.common.EjbFactory.getObjectInstance(EjbFactory.java:50)
at org.apache.naming.factory.EjbFactory.getObjectInstance(EjbFactory.java:161)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at org.apache.jsp.openejb_jsp._jspService(openejb_jsp.java:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
and in openejb.log,getting :
Deployed Application(path=D:apache-tomcat-6.0.32webappsdocs)
2011-08-01 18:06:38,445 - INFO - Configuring enterprise application: D:apache-tomcat-6.0.32webappsexamples
2011-08-01 18:06:38,821 - WARN - Unresolved ejb reference "ejb/Hello" in bean "D:apache-tomcat-6.0.32webappsexamples". Will attempt resolution again at runtime.
2011-08-01 18:06:38,821 - INFO - Enterprise application "D:apache-tomcat-6.0.32webappsexamples" loaded.
2011-08-01 18:06:38,821 - INFO - Assembling app: D:apache-tomcat-6.0.32webappsexamples
Could anybody put some light where did i make mistake ? :(
将myHelloEjb.jar放到示例webapp的WEB-INF/lib/目录中,它应该可以工作了。
您写的:
<ejb-local-ref>
<ejb-ref-name>ejb/Hello</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>org.acme.HelloHome</local-home>
<local>org.acme.HelloHome</local>
</ejb-local-ref>
看起来你的问题可能是(可能是)如下:
<local>org.acme.HelloHome</local>
而不是:
<local>org.acme.Hello</local>
没有?