• Post Reply Bookmark Topic Watch Topic
  • New Topic

The EJB3.1 Naming Conundrum

 
Perry Terrance
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been a while since I had been in EJB land - and now I am using the latest and greatest EJB3.1.

So naturally I get stumped by some basic things (again):

My EJB3.1 setup is like so:

MyManagedBean.java which implements LocalInterface.java interface methods (with @Stateless Annotation)
LocalInterface.java with interface methods (with @Local Annotation)

Now this whole thing is packed in an EJB-JAR file along with a WAR which is then bundled inside an EAR and crammed into my JBoss server.

So the packaging is like so:
EAR PACKAGE ->
EJB-JAR PACKAGE
WAR PACKAGE

In the WAR package - I have a controller that is using InitialContext lookup to find the EJB bundled in the EAR (and thus use it - of course).

Imagine to my surprise that this doesn't actually work!

I am using a lookup with the name
"java:global/myproject-ear-0.0.1-SNAPSHOT/myproject-ejb-0.0.1-SNAPSHOT/MyManagedBean!com.myproject.bean.MyManagedBean"

The error would say:

javax.naming.NameNotFoundException: myproject-ear-0.0.1-SNAPSHOT/myproject-ejb-0.0.1-SNAPSHOT/MyManagedBean!com.myproject.bean.MyManagedBean -- service jboss.naming.context.java.global."myproject-ear-0.0.1-SNAPSHOT"."myproject-ejb-0.0.1-SNAPSHOT"."MyManagedBean!com.myproject.bean.MyManagedBean"

Now here's the kicker:

After tinkering around with it - I found that if I ONLY add the additional annotation of @LocalBean on the MyManagedBean.java class - and restart the JBoss server again - it would find the Name!

Yet according to my research - the whole @LocalBean annotation is redundant and unnecessary since I already am implementing a LocalInterface with @Local anyways.

So whats the deal here?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am using a lookup with the name
"java:global/myproject-ear-0.0.1-SNAPSHOT/myproject-ejb-0.0.1-SNAPSHOT/MyManagedBean!com.myproject.bean.MyManagedBean"


You are using an incorrect JNDI name (as the error message states). The syntax is:

java:global/<app-name>/<module-name>/<bean-name>!<fully-qualified-business-interface-class-name>

You note that:

MyManagedBean.java which implements LocalInterface.java interface methods (with @Stateless Annotation)
LocalInterface.java with interface methods (with @Local Annotation)


So your JNDI name should be:



Assuming com.myproject.bean.LocalInterface is the fully qualified classname of your local business interface.
 
Michael Remijan
Author
Ranch Hand
Posts: 131
7
Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't be using JNDI. It has its uses but not in this case. If your bean's interface is LocalInterface.java, then inject it with either:

@Inject LocalInterace myBean

or

@EJB LocalInterface myBean


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