3

Folks,

I am very annoyed by having to re-learn and waste time with this stuff every time a new version of JBoss rolls around.

I have a stateless EJB that is discovered and declared in the JNDI space:

10:01:53,044 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

DTalk/UserManager/local - EJB3.x Default Local Business Interface
DTalk/UserManager/local-com.doctalk.ejb.UserManagerLocal - EJB3.x Local Business Interface

I need to use this EJB in a servlet which is part of a war which is part of the EAR that contains the EJB. I'd like to do it using injection.

When I use the most intuitive notation:

@EJB
private UserManager userManager;

I get an exception in JBoss logs.

When I use a more flowery notation such as:

@EJB( mappedName = "UserManager" )
private UserManager userManager;

Or

@EJB( mappedName = "DTalk/UserManager/local" ) // EAR is called DTalk
private UserManager userManager;

I get no injections errors in jboss but the injected bean is null.

This is maddening and a huge waste of time and makes me question why I don't dump the Eclipse/jboss tools franchise in favor of NetBeans and GlsssFish.

Any insights appreciated.

Thanks.

Raj
  • 2,852
  • 4
  • 29
  • 48
  • 1
    You seem to have a variety of misconceptions that need to be cleared up. The "new stuff" you are loathe to re-learn are independent of JBoss. They reflect new Java specifications. New versions of GlassFish will, in theory, be updated to support the same new JSRs as JBoss. No one is forcing you to use the new version of JBoss, right? Also, you don't use Eclipse/JBoss as a pair, or NetBeans/GlassFish as a pair. The application servers are completely interoperable with any of the major IDEs. – Matt Ball Jul 26 '11 at 17:24
  • Hi Matt, Thanks for writing. Since I made an unhelpful rant, I deserve an unhelpful response back. However, your comment about app servers being interoperable with major IDEs is a little idealistic. They *may* be made to interoperate if you enjoy that type of stuff, or, say stapling your ears to the wall. That being said, do you have an answer for me, or only the rant-back? – Raj Jul 26 '11 at 18:05
  • What's the exception you get when using the minimal `@EJB private UserManager userManager;` injection? – Matt Ball Jul 26 '11 at 18:10
  • Hi Matt, I was using the bean class in the servlet when I should have been referring to the local interface. Once again, thanks for your response. – Raj Jul 26 '11 at 19:09

1 Answers1

5

You are trying to inject (a proxy to) the bean instance itself, instead of its interface.

Yet, according to the deployment logging you've shown, you have only declared the bean to be bounded in JNDI via its (local) interface. In order to make the injection happen, you should either declare the variable in which you're injecting as the interface:

@EJB
private UserManagerLocal userManager;

OR declare that a no-interface view should be created for your bean:

@Stateless
@LocalBean
public class UserManager implements UserManagerLocal {
    ...
}

after which you can declare the variable as you did earlier:

@EJB
private UserManager userManager;
Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • Arjan, Thanks for a very accurate and direct answer. You caught the root cause: I was referring to the bean class not the interface. Thanks also for making me aware of the EJB3.1 no-interface view. I will check this out as well. – Raj Jul 26 '11 at 19:08