• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting error javax.naming.NameNotFoundException

 
Rohit W. Tawde
Greenhorn
Posts: 25
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a local interface and a stateless session bean which implements that interface (Eclipse 3.8.2 and JBoss AS 7.1, EJB 3.1)
I call the bean through a servlet using JNDI,
Below is the code snippet,

Context initialContext = new InitialContext();
TestSessionBeanLocal testSessionBeanLocal= (TestSessionBeanLocal) initialContext.lookup("TestEJB/TestSessionBean/local");
out.println(testSessionBeanLocal.beanMethod());


I am getting the following error,
javax.naming.NameNotFoundException: TestEJB/TestSessionBean/local -- service jboss.naming.context.java.TestEJB.TestSessionBean.local


Kindly help.
 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Posting code snippets of your interface, session bean etc. with the annotations used will give more clarity on what's being done.
And, an additional help tip. If you want to actually check whether your session bean is deployed fine and the binding has happening as you excepted or not, you can look at the JNDI tree of the JBoss from its jmx-console. You can search for details on how to get there
 
Rohit W. Tawde
Greenhorn
Posts: 25
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its easy to implement it in NetBeans.(using insert code and calling enterprise bean).
I am trying it to do it in Eclipse.(Was able to do it using Dependency Injection. @EJB annotation and placing the jar file of the bean in the WEB-INF/lib folder of the Web Content.)

But i am not able to do it using the JNDI way as mentioned in the previous post.

Here are my code snippets,
local bean interface
<CODE>
package com.rohit.ejbs;

import javax.ejb.Local;

@Local
public interface TestSessionBeanLocal {

String beanMethod();

}
</CODE>

Stateless session bean
<CODE>
package com.rohit.ejbs;

import javax.ejb.Local;
import javax.ejb.Stateless;

@Stateless(name="TestSession")
@Local(TestSessionBeanLocal.class)
public class TestSessionBean implements TestSessionBeanLocal{

@Override
public String beanMethod() {

return "Testing my first EJB in Eclipse using JBoss AS 7.1";
}

}
</CODE>

And the GET method code snippet of the servlet,
<CODE>
Context initialContext = new InitialContext();

TestSessionBeanLocal testSessionBeanLocal= (TestSessionBeanLocal) initialContext.lookup("TestEJB/TestSessionBean/local");

out.println(testSessionBeanLocal.beanMethod());
</CODE>

Actually was just following this - http://www.half-wit4u.blogspot.in/2012/02/ejb3-simplified-approach.html
 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



If I am not wrong, either changing the name="TestSession" to name="TestSessionBean"
Or changing the lookup string "TestEJB/TestSessionBean/local" to "TestEJB/TestSession/local"
should get this working.

And, if it still doesn't work, do have a look at the jndi view of the JBoss after the bean is deployed.
 
Rohit W. Tawde
Greenhorn
Posts: 25
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have tried both ways, but it still gives the same error.
19:04:00,590 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) javax.naming.NameNotFoundException: TestEJB/TestSession/local -- service jboss.naming.context.java.TestEJB.TestSession.local


Also i tries this, http://localhost:8080/jmx-console

But it gives me HTTP Status 404 - /jmx-console

Please help
 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I hope the deployment structure(war, ear, ejb etc.) is proper as per the example you are following and the ear is named "TestEJB".
If jmx-console is not working, then its worth checking if JBoss is started and running fine or not..
 
Rohit W. Tawde
Greenhorn
Posts: 25
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have checked the application structure, it is fine.

JBoss is running but still i cant open the jmx console.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!