aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes First Session Bean failing in JBOSS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "First Session Bean failing in JBOSS" Watch "First Session Bean failing in JBOSS" New topic
Author

First Session Bean failing in JBOSS

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1075
Hello,

I'm new to EBJ3 and am getting this error trying to get a basic session bean to work under JBOSS 4.2.1:

"javax.naming.NameNotFoundException: com.testDomain.domain.TravelAgentRemote not bound"

My Client code, which compiles and deploys fine, is this:
------------------------------------------------------

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class EJBBeanTest
{

/**
* @param args
*/
public static void main(String[] args)
{
try
{
InitialContext ctx = (InitialContext) getInitialContext();

TravelAgentRemote bean = (TravelAgentRemote) ctx.lookup("com.testDomain.domain.TravelAgentRemote");
bean.doSomething();
}
catch (NamingException e)
{
e.printStackTrace();
}
} // end main

// -------------------------------------------------------------------------------------------------------------

public static Context getInitialContext() throws javax.naming.NamingException
{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");
p.put(Context.PROVIDER_URL,"jnp://localhost:1099");
return new javax.naming.InitialContext(p);
}
}

=================================

The TravelAgentRemote interface is this:

@Remote
public interface TravelAgentRemote extends ITravelAgent
{

}

=================================

The ITravelAgent Interface is this:

public interface ITravelAgent extends Serializable
{
public void doSomething();
}

==================

The actual EJB bean is this:

import javax.ejb.Stateless;

@Stateless
public class TravelAgent implements TravelAgentLocal, TravelAgentRemote
{

public void doSomething()
{
System.out.println("Hello World from Stateless EBJ3 Bean");
}

}

====================================


Any help or suggestions would be appreciated.
Thanks. M
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10207
    
166

Whats the name of your application? If its named myApp.ear, then your lookup for the remote bean should be:



[My Blog] [JavaRanch Journal]
Michael Ernst
Greenhorn

Joined: Jul 03, 2005
Posts: 23
You can use the
@org.jboss.annotation.ejb.RemoteBinding(jndiBinding = "TravelAtentRemote")
@org.jboss.annotation.ejb.LocalBinding(jndiBinding = "TravelAgentLocal")
Annotations (at the Bean class) to set your prefered JNDI name.

Instead of your getInitialContext Method you can use a jndi.properties File (placed inside your classpath; IDE source folder). "new InitialContext()" is enough to get your Context object.

Regards
Michael
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1075
Thanks for your reply. I'm sure this lookup issue is a minor (common newbie) issue.

Currently, I'm "deploying" this Session Bean as class files using MyEclipse's debug "hot" deployment. No EAR file. I'm not sure if hot deployment (class files and no EAR) is "allowed" with JBOSS. Must I deploy an EJB jar file or can I deploy regular class files?

In any case, if I change my look up to this (or anything else I tried):

TravelAgentRemote bean = (TravelAgentRemote) ctx.lookup("TravelAgent/remote");

I still get:

javax.naming.NameNotFoundException: TravelAgent not bound


---------------

I'm still trying to use the JNDI JBOSS code from chapter 4, page 59 of "Enterprise JavaBeans 3". If that doesn't work, I don't see yet the point of using a jndi.properties file to get the same errors. I also tried the annotations mentioned, but these are not in the EJB3 book and give "cannot resolve to a type" error messages.

Thanks in advance for additional assistance.

M
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10207
    
166

The best option that you have to figure out the jndi name of the bean, is to follow the steps below:

- Go to http://localhost:8080/jmx-console
- Search for service=JNDIView
- Click on that link
- On the page that comes up click on the Invoke button beside the list() method
- The page that comes up will show the contents of the JNDI tree.

On this page, you will be able to find the TravelAgent bean and its jndi name. If you have problems understanding the JNDI tree, just post the above output, here.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1075
Hey, this worked!

Thank you so very much!!!

My next step is to get a basic Entity Bean working from Chapter 4 of this book.

Hopefully, it won't be that difficult.

I'll post additional questions.

Thanks again!!!

M
sab vas
Greenhorn

Joined: Sep 20, 2010
Posts: 3
HI!

Me to facing the same problem, I am on EJB3 on JBOSS 5. I get the following exception, when i run
ant run.client

javax.naming.NameNotFoundException: TravelAgentBean not bound



I followed the above steps

Go to http://localhost:8080/jmx-console
- Search for service=JNDIView
- Click on that link
- On the page that comes up click on the Invoke button beside the list() method
- The page that comes up will show the contents of the JNDI tree.


here is the output:



Other components with java:comp namespace


java: Namespace


+- securityManagement (class: org.jboss.security.integration.JNDIBasedSecurityManagement)
+- comp (class: javax.namingMain.Context)
+- XAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
+- TransactionPropagationContextImporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
+- policyRegistration (class: org.jboss.security.plugins.JBossPolicyRegistration)
+- ClusteredConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- Mail (class: javax.mail.Session)
+- TransactionPropagationContextExporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
+- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
+- jaas (class: javax.naming.Context)
| +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
+- ClusteredXAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- TransactionSynchronizationRegistry (class: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple)
+- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
+- ConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
+- TransactionManager (class: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate)
+- timedCacheFactory (class: javax.naming.Context)
Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy cannot be cast to javax.naming.NamingEnumeration

Global JNDI Namespace


+- UserTransactionSessionFactory (proxy: $Proxy122 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
+- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
+- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
+- XAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- topic (class: org.jnp.interfaces.NamingContext)
+- ClusteredConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- queue (class: org.jnp.interfaces.NamingContext)
| +- DLQ (class: org.jboss.jms.destination.JBossQueue)
| +- ExpiryQueue (class: org.jboss.jms.destination.JBossQueue)
+- ClusteredXAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
+- ConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
+- jmx (class: org.jnp.interfaces.NamingContext)
| +- invoker (class: org.jnp.interfaces.NamingContext)
| | +- RMIAdaptor (proxy: $Proxy121 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)
+- TomcatAuthenticators (class: java.util.Properties)
+- console (class: org.jnp.interfaces.NamingContext)
| +- PluginManager (proxy: $Proxy123 implements interface org.jboss.console.manager.PluginManagerMBean)



I am trying the example for chap 4 in Enterprise Java bean 3.0 O'Really:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
my client.java

public class Client
{
public static void main(String [] args)
{
try
{
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("TravelAgentBean/remote");
TravelAgentRemote dao = (TravelAgentRemote)ref;
......


Please help me out and let me know, where i have gone wrong.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: First Session Bean failing in JBOSS