[jboss-user] [Beginners Corner] - comp not bound

raysonliu do-not-reply at jboss.com
Fri Jul 28 17:24:52 EDT 2006


Hi,
I've been trying the following project on Jboss ( initially from SUN J2EE tutorial ). Depolyment of EJB to Jboss is ok, but when I try the ConverterClient, I got the following error:

Caught an unexpected exception!
javax.naming.NameNotFoundException: comp not bound
	at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
	at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
 ...



-------------------------- Source Code start ---------------


Converter.java


  |  
  | package converter;
  |  
  | import javax.ejb.EJBObject;
  | import java.rmi.RemoteException;
  | import java.math.*;
  | 
  | public interface Converter extends EJBObject {
  |     public BigDecimal dollarToYen(BigDecimal dollars) throws RemoteException;
  | 
  |     public BigDecimal yenToEuro(BigDecimal yen) throws RemoteException;
  | }
  | 
  | 


ConverterHome.java


  | package converter;
  | 
  | import java.rmi.RemoteException;
  | import javax.ejb.CreateException;
  | import javax.ejb.EJBHome;
  | 
  | public interface ConverterHome extends EJBHome {
  |     Converter create() throws RemoteException, CreateException;	
  | }
  | 
  | 


ConverterBean.java


  | package converter;
  | 
  | import java.rmi.RemoteException;
  | import javax.ejb.SessionBean;
  | import javax.ejb.SessionContext;
  | import java.math.*;
  | 
  |  public class ConverterBean implements SessionBean {
  | 	BigDecimal yenRate = new BigDecimal("121.6000");
  | 	BigDecimal euroRate = new BigDecimal("0.0077");
  | 	
  | 	public BigDecimal dollarToYen(BigDecimal dollars) {
  | 		BigDecimal result = dollars.multiply(yenRate);
  | 		return result.setScale(2,BigDecimal.ROUND_UP);
  | 	}
  | 
  | 	public BigDecimal yenToEuro(BigDecimal yen) {
  | 		BigDecimal result = yen.multiply(euroRate);
  | 		return result.setScale(2,BigDecimal.ROUND_UP);
  | 	}
  | 
  | 	public ConverterBean() {}
  | 	public void ejbCreate() {}
  | 	public void ejbPostCreate() {}
  | 	public void ejbRemove() {}
  | 	public void ejbActivate() {}
  | 	public void ejbPassivate() {}
  | 	public void setSessionContext(SessionContext sc) {}
  | }
  | 
  | 

ConverbeanHome.java


  |  
  | package converter;
  | 
  |  public interface ConverterBeanHome
  |    extends javax.ejb.EJBHome
  | {
  |    public static final String COMP_NAME="java:comp/env/ejb/ConverterBean";
  |    public static final String JNDI_NAME="ejb/ConverterBean";
  | 
  |    public converter.ConverterBean create()
  |       throws javax.ejb.CreateException,java.rmi.RemoteException;
  | 
  | }
  | 

ejb-jar.xml

  | <?xml version="1.0" encoding="UTF-8"?>
  | 
  | <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
  | 
  | <ejb-jar >
  | 
  |    <description><![CDATA[No Description.]]></description>
  |    <display-name>Generated by XDoclet</display-name>
  | 
  |    <enterprise-beans>
  | 
  |       <!-- Session Beans -->
  |       <session >
  |          <description><![CDATA[Description for test]]></description>
  |          <display-name>Name for test</display-name>
  | 
  |          <ejb-name>ConverterBean</ejb-name>
  | 
  |          <home>converter.ConverterHome</home>
  |          <remote>converter.Converter</remote>
  |          <ejb-class>converter.ConverterBean</ejb-class>
  |          <session-type>Stateless</session-type>
  |          <transaction-type>Container</transaction-type>
  | 
  |       </session>
  |     </enterprise-beans>
  |  
  | </ejb-jar>
  | 

jboss.xml

  | <?xml version="1.0" encoding="UTF-8"?>
  | <!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
  | 
  | <jboss>
  |    <enterprise-beans> 
  |       <session>
  |          <ejb-name>ConverterBean</ejb-name>
  |          <jndi-name>ejb/ConverterBean</jndi-name>
  | 
  |         <method-attributes>
  |         </method-attributes>
  |       </session>  
  |    </enterprise-beans> 
  | </jboss>
  | 


ConverterClient.java

  | 
  | import converter.Converter;
  | import converter.ConverterHome;
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | import javax.rmi.PortableRemoteObject;
  | import java.math.BigDecimal;
  | 
  | 
  | 
  | public class ConverterClient {
  |     public static void main(String[] args) {
  |         try {
  |             Context initial = new InitialContext();                    	
  |             Context myEnv = (Context) initial.lookup("java:comp/env");
  |             Object objref = myEnv.lookup("ejb/ConverterBean");
  | 
  |             ConverterHome home =
  |                 (ConverterHome) PortableRemoteObject.narrow(objref,
  |                     ConverterHome.class);
  | 
  |             Converter currencyConverter = home.create();
  | 
  |             BigDecimal param = new BigDecimal("100.00");
  |             BigDecimal amount = currencyConverter.dollarToYen(param);
  | 
  |             System.out.println(amount);
  |             amount = currencyConverter.yenToEuro(param);
  |             System.out.println(amount);
  | 
  |             System.exit(0);
  |         } catch (Exception ex) {
  |             System.err.println("Caught an unexpected exception!");
  |             ex.printStackTrace();
  |         }
  |     }
  | }
  | 

-------------------------- Source Code end ---------------

Anybody please help, thanks a lot in advance.


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

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



More information about the jboss-user mailing list