[jboss-user] [EJB 3.0] - Can't get a stateless session bean to work - JNDI can't find

Azavia do-not-reply at jboss.com
Thu Nov 16 21:14:53 EST 2006


Hi,

I've been trying to create a very simple example of a stateless session bean in EJB3. I get the following error:

exception 
  | 
  | org.apache.jasper.JasperException: Exception in JSP: /index.jsp:14 
  | 11: <body>
  | 12: <%
  | 13: InitialContext context = new InitialContext();
  | 14: Math math = (Math)context.lookup("Math/MathBean/remote");
  | 15: %>
  | 16: <p>2 + 2: <%=math.add(2, 2) %>.</p>
  | 17: </body>  
  | Stacktrace:
  | 	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
  | 	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
  | 	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  | 	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  | 	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
  | 	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 
  | root cause 
  | 
  | javax.servlet.ServletException: remote not bound
  | 	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
  | 	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
  | 	org.apache.jsp.index_jsp._jspService(index_jsp.java:69)
  | 	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  | 	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
  | 	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
  | 	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  | 	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  | 	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
  | 	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 
  | root cause 
  | 
  | javax.naming.NameNotFoundException: remote not bound
  | 	org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
  | 	org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
  | 	org.jnp.server.NamingServer.getObject(NamingServer.java:543)
  | 	org.jnp.server.NamingServer.lookup(NamingServer.java:296)
  | 	org.jnp.server.NamingServer.lookup(NamingServer.java:270)
  | 	org.jnp.server.NamingServer.lookup(NamingServer.java:270)
  | 	org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
  | 	org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
  | 	javax.naming.InitialContext.lookup(Unknown Source)
  | 	org.apache.jsp.index_jsp._jspService(index_jsp.java:56)
  | 	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  | 	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
  | 	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
  | 	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  | 	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  | 	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
  | 	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

JDK version is 1.6, working with JBoss 4.0.5, JBoss EJB3 RC9, and the JBoss Eclipse IDE.

I've deployed the ear and war files. When that didn't work, I also deployed the jar file. I have MathEJB.jar containing the bean, MathWeb.war containing the web files (index.jsp), and Math.ear containing MathEJB.jar, MathWeb.war, and application.xml.

I've been somewhat following http://docs.jboss.org/ejb3/app-server/tutorial/stateless/stateless.html.

I should also note that JBoss Eclipse IDE won't automatically deploy the files; I have to manually copy them. When I try to "run" them, it says those  type of modules can't run.

Apparently I can't attach files, so I'll copy the code.

Math/src/com/azavia/math/Math.java:

package com.azavia.math;
  | 
  | import javax.ejb.Remote;
  | 
  | @Remote
  | public interface Math {
  |     
  |     int add(int a, int b);
  | 
  | }
  | 

Math/src/com/azavia/math/MathBean.java:

package com.azavia.math;
  | 
  | import java.io.Serializable;
  | 
  | import javax.ejb.Stateless;
  | 
  | @Stateless
  | public class MathBean implements Math, Serializable {
  |     
  |     /**
  |      * Serial version UID
  |      * 
  |      * Field used for serialization
  |      */
  |     private static final long serialVersionUID = 2976407238222758431L;
  | 
  |     public int add(int a, int b) {
  | 	return a + b;
  |     }
  | 
  | }
  | 

Math/docroot/index.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  |     pageEncoding="ISO-8859-1"%>
  | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  | <%@page import="javax.naming.InitialContext"%>
  | <%@page import="com.azavia.math.Math"%>
  | <html>
  | <head>
  | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  | <title>Math</title>
  | </head>
  | <body>
  | <%
  | InitialContext context = new InitialContext();
  | Math math = (Math)context.lookup("Math/MathBean/remote");
  | %>
  | <p>2 + 2: <%=math.add(2, 2) %>.</p>
  | </body>
  | </html>

Math/src/META-INF/application.xml:

<?xml version="1.0" encoding="UTF-8"?>
  | <application version="1.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/j2ee
  | 	http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
  | 	<display-name>Math</display-name>
  | 	<module>
  | 		<ejb>MathEJB.jar</ejb>
  | 	</module>
  | 	<module>
  | 		<web>
  | 			<web-uri>MathWeb.war</web-uri>
  | 			<context-root>/math</context-root>
  | 		</web>
  | 	</module>
  | </application>
  | 

Thanks for any help.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3986727#3986727

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3986727




More information about the jboss-user mailing list