File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JBoss/WildFly and the fly likes Problem with EJB lookup on JBoss 7.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Problem with EJB lookup on JBoss 7.1" Watch "Problem with EJB lookup on JBoss 7.1" New topic
Author

Problem with EJB lookup on JBoss 7.1

Rodrigo Sasaki
Greenhorn

Joined: Mar 09, 2012
Posts: 24
I don't know if this post should be here or on JBoss Forums. but here I go

I'm trying to do an EJB lookup on JBoss 7.1.0 like this:



which works fine on GlassFish, but didn't work on JBoss... when I get to the lookup line it just "freezes" waiting for a response I imagine, and the deployment times out..

then I read this thread, explaining how to do it.. then I tried it like this



and still.. same problem..

don't know how to fix this, has anybody had a problem like this here?

here is the EJB classes.. in case there is anything relevant there



and the implementation



the ejb.module is in a .jar inside my ear

Thanks!
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

I believe JBoss 7 logs all EJB JNDI names at startup, for local and remote lookups.
That might be worth checking out in the server.log file.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Rodrigo Sasaki
Greenhorn

Joined: Mar 09, 2012
Posts: 24
True...

I checked it and the JNDI lookup name is exactly how I was using it..

java:global/my-ear-app/my-ejb-module/FriendBOImpl

that's what I don't understand, I try the lookup and it just freezes, don't know if I'm missing configurations on JBoss or on the EJB
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

You said you were "trying to do an EJB lookup on JBoss 7.1.0", but from the code sample you provided it looks like you're using the JBoss client API to do a remote lookup, correct? From a standalone client?

Rodrigo Sasaki
Greenhorn

Joined: Mar 09, 2012
Posts: 24
First.. sorry about the duplicate, I'm new at Javaranch.. it won't happend again.

Second,

I have a classe in my model package doing the lookup, so I guess you are right.

The actual problem is that it worked on GlassFish, and now that I'm using JBoss 7.1.0 it doesn't work anymore.

Any idea what it might be?
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

A class in your model package is doing the JNDI lookup, and that package is part of the deployment to JBoss?
You said the EJB you're trying to lookup is packaged in a .jar file within an .ear archive.
Is you model package in that same .jar file? Or maybe packaged in of a .war file included in the .ear or deployed separately?
Perhaps we should start with how your deployment(s) is/are structured and take it from there.
Rodrigo Sasaki
Greenhorn

Joined: Mar 09, 2012
Posts: 24
You can probably tell.. I'm "junior" at all this hehe..
Never done any work with EJB before, so I'm sorry if I say any stupid things..

the ear has the following structure:



any notes?
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1753
    
    7

Right, so you want to do a look-up of an EJB packaged inside the market-cadastro-ejb.jar archive from a class inside the market-web.war that's part of the same .ear deployment.
A local JNDI lookup should work in that case using the java:app namespace, but I would take a different approach altogether.
Instead of manually performing a look-up that couples your code to JNDI, in my opinion, you'd be better of using dependency injection and have JBoss figure out how to obtain a reference to the EJB (via JNDI somwhere in the background). Have a look at the @EJB and @Inject annotations


Rodrigo Sasaki
Greenhorn

Joined: Mar 09, 2012
Posts: 24
hey.. I tried using @Inject on my attribute, just adding the annotation like this:



and it didn't work, the attribute was null and I got this error:



I even made a qualifier to try to fix this but it didn't work, any ideas?

I'll keep looking into it, see what I can find
Rodrigo Sasaki
Greenhorn

Joined: Mar 09, 2012
Posts: 24
Can't get it to work..

but then again.. why isn't my lookup working the same way it was before on GlassFish?

is it wrong to do a lookup like that on JBoss?
Rodrigo Sasaki
Greenhorn

Joined: Mar 09, 2012
Posts: 24
Oh.. I see what you meant.. the Injection was just a suggestion for better use of the technology..

but I tried the static way and it didn't work.. JBoss gave me these JNDI names:

java:global/market-ear/market-cadastro-ejb/MarketBOImpl!br.com.vemac.nagumo.model.bean.vo.sistema.MarketBO
java:app/market-cadastro-ejb/MarketBOImpl!br.com.vemac.nagumo.model.bean.vo.sistema.MarketBO
java:module/MarketBOImpl!br.com.vemac.nagumo.model.bean.vo.sistema.MarketBO
java:jboss/exported/market-ear/market-cadastro-ejb/MarketBOImpl!br.com.vemac.nagumo.model.bean.vo.sistema.MarketBO
java:global/market-ear/market-cadastro-ejb/MarketBOImpl
java:app/market-cadastro-ejb/MarketBOImpl
java:module/MarketBOImpl


but the ones with java:app

cause the following exception:



and the other ones give me the "freezing" error
Joshua Davis
Greenhorn

Joined: Nov 26, 2010
Posts: 4
Jelle Klap wrote:Right, so you want to do a look-up of an EJB packaged inside the market-cadastro-ejb.jar archive from a class inside the market-web.war that's part of the same .ear deployment.
A local JNDI lookup should work in that case using the java:app namespace, but I would take a different approach altogether.
Instead of manually performing a look-up that couples your code to JNDI, in my opinion, you'd be better of using dependency injection and have JBoss figure out how to obtain a reference to the EJB (via JNDI somwhere in the background). Have a look at the @EJB and @Inject annotations


Jelle is right. Using EJBs deployed in an EAR from the WAR deployed in the same EAR is best done by injection. Without knowing why you're doing a JNDI lookup, or what kind of object needs the EJB, it's really hard to offer any more help.

@Inject is a CDI annotation. If you want to use that, you'll have to set up CDI in your application and learn to use it (I highly recommend this). I don't see enough information about the packaging to tell.

@EJB is an EJB3 annotation. This should work if your application is packaged properly. However, I've noticed that your EJB is stateful. That can change things a little because the container needs to know more about the state of the thing that is injecting the EJB.

Either way, most of the time you should not need to do any JNDI lookups inside a JEE6 application.
 
 
subject: Problem with EJB lookup on JBoss 7.1
 
Similar Threads
Simple EJB3 session beans not deploying in JBOSS6
Help needed to deploy HelloWorld EJB
Ejb stand alone client question
EJB3.0 & calling remote interface.