This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

The EJB3.1 Naming Conundrum

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 131
7
Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
This guy is skipping without a rope. At least, that's what this tiny ad said:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic