java:comp/env problem
ochta Mar 15, 2006 7:42 PMFolks,
sorry for the blast I am new to JBoss and I've got a problem with the small application I wrote just to see how it works. I created simple stateless bean
Interface One.java:
package com.documentum.ejb;
public interface One
{
public String sayHello ();
}
Implementation OneBean.java:
package com.documentum.ejb;
import javax.ejb.Stateless;
import javax.ejb.Remote;
import javax.ejb.Local;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@Remote (com.documentum.ejb.One.class)
@Local (com.documentum.ejb.One.class)
@Stateless
public class OneBean
{
public String sayHello()
{
try
{
Context ctx = new InitialContext ();
String str = (String) ctx.lookup("java:comp/env/frase");
if (str.length() == 0)
str = "Nothing in the String";
return str;
}
catch (NamingException e)
{
e.printStackTrace();
}
return null;
}
}
and my deployment descriptor ejb-jar.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
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"
version="3.0">
<enterprise-beans>
<ejb-name>OneEJB</ejb-name>
<ejb-class>com.documentum.ejb.OneBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>frase</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Hello Guys</env-entry-value>
</env-entry>
</enterprise-beans>
<assembly-descriptor>
</assembly-descriptor>
</ejb-jar>
To test this bean I use following client:
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class EjbClient
{
public static void main(String[] args)
{
try
{
InitialContext ctx = new InitialContext();
One stub = (One) ctx.lookup("OneBean/remote");
System.out.println("Ejb said : " + stub.sayHello());
}
catch (NamingException e)
{
e.printStackTrace();
}
}
}
When I install my bean it gets deployed without a problem but when I run my client application I am getting null returned from the bean. When I look into JBoss console I see following error:
16:37:55,343 ERROR [STDERR] javax.naming.NameNotFoundException: env not bound
When I debug my bean I see that this exception gets thrown when I call
String str = (String) ctx.lookup("java:comp/env/frase");
I would greatly appreciate any help
Regards