Missing EJB 3.0 Session bean name in Global JNDI Namespace!!
benix Oct 29, 2007 8:13 AMI have created an ear ?SampleEnterprise.ear? which consists of an ejb jar ?SampleEnterprise-ejb.jar? and a war file ?SampleEnterprise-war.war?. The ear file was deployed on a JBoss 4.0.5 server.
There is a EJB 3.0 stateless session bean ?EmployeeServiceBean? present in the ejb jar file which I need to access from a servlet ?EmployeeServlet? in the war file
Here?s the code from the servlet used to lookup the session bean
try {
Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");
Context context = new InitialContext(properties);
EmployeeServiceRemote empService = (EmployeeServiceRemote)context.lookup("SampleEnterprise/EmployeeServiceBean/remote");
} catch (Exception e) {}
Here's the session bean
package sessionBeans;
import entityBeans.Employee;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless()
public class EmployeeServiceBean implements EmployeeServiceLocal, EmployeeServiceRemote {
@PersistenceContext()
EntityManager em;
public EmployeeServiceBean() {}
public Employee createEmployee(int id, String name, int salary) {
Employee emp = new Employee(id);
emp.setName(name);
emp.setSalary(salary);
em.persist(emp);
return emp;
}
here's the JndiView
Global JNDI Namespace +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair) +- jmx (class: org.jnp.interfaces.NamingContext) | +- invoker (class: org.jnp.interfaces.NamingContext) | | +- RMIAdaptor (proxy: $Proxy42 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt) | +- rmi (class: org.jnp.interfaces.NamingContext) | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef) +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory) +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory) +- UserTransactionSessionFactory (proxy: $Proxy12 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory) +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory) +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory) +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction) +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef) +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef) +- queue (class: org.jnp.interfaces.NamingContext) | +- A (class: org.jboss.mq.SpyQueue) | +- testQueue (class: org.jboss.mq.SpyQueue) | +- ex (class: org.jboss.mq.SpyQueue) | +- DLQ (class: org.jboss.mq.SpyQueue) | +- D (class: org.jboss.mq.SpyQueue) | +- C (class: org.jboss.mq.SpyQueue) | +- B (class: org.jboss.mq.SpyQueue) +- topic (class: org.jnp.interfaces.NamingContext) | +- testDurableTopic (class: org.jboss.mq.SpyTopic) | +- testTopic (class: org.jboss.mq.SpyTopic) | +- securedTopic (class: org.jboss.mq.SpyTopic) +- console (class: org.jnp.interfaces.NamingContext) | +- PluginManager (proxy: $Proxy43 implements interface org.jboss.console.manager.PluginManagerMBean) +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef) +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory) +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef) +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair) +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
however the EmployeeServiceBean does not appear in the above listing and I get the following exception when the lookup code is executed
javax.naming.NameNotFoundException: SampleEnterprise not bound
do i need to add any references to the session bean in the following files?
jboss-app.xml (is a <loader-repository> required?)
jboss.xml
jboss-web.xml
ejb-jar.xml
web.xml
or have i missed out something else?
there aren't any exceptions during deployment