• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointer on Simple EJB injection

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am receiving nullpointer when I execute my main test that execute a EJB method. So with sure the problem is that the injection it's not working!
(The container is Sun App Server 9 and I'm running the test in eclipse)

Should I configure JNDI or initial context for the injection work?

If somebody have a simple example of JNDI configuration for a simple remote client that use EJB 3 I thank.

Thank-you
 
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
Please post the code and the exception stacktrace so that someone will be able to figure out what the problem is.
 
Jaikiran Pai
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

If somebody have a simple example of JNDI configuration for a simple remote client that use EJB 3 I thank.



When you say, remote client, is it a standalone java program? If yes then i dont think injection is supported in such standalone java client. You will have to create an application-client which can rely on dependency injection. If you are sticking to standalone program then i guess the JNDI lookup approach is what you will have to follow
 
Luciano A. Pozzo
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Jaikiran Pai

The stack trace is just java.lang.NullPointerException. And yes, it's a standalone java client.
So, dependency injection work only with another EJB's inside of my container? And about the servlets?
And in standalone clients I have to use the old look up? (InitialContext)

Thank-you
 
Jaikiran Pai
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

So, dependency injection work only with another EJB's inside of my container? And about the servlets?


Servlets can use dependency injection.

And in standalone clients I have to use the old look up? (InitialContext)


Thats the only option as far as i know.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which application server you are using?

I had this same problem with JBoss. Current version (4.0.5.GA) is using Tomcat 5.5(?) as it's servlet container and this Tomcat version doesn't support @EJB annotation yet. This support should come in Tomcat 6.0.
[ November 08, 2006: Message edited by: Sami Kosonen ]
 
Jaikiran Pai
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 have had this problem with JBoss. Current version (4.0.5.GA) is using Tomcat 5.5(?) as it's servlet container and this Tomcat version doesn't support @EJB annotation yet. This support should come in Tomcat 6.0.



You are right as far as injection of EJBs into servlets is concerned, on JBoss.
The issue which Luciano A. Pozzo is running into has more to do with standalone Java clients.
 
Sami Kosonen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes... I should have read the original posting again before answering.
[ November 08, 2006: Message edited by: Sami Kosonen ]
 
author
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Injection into client programs is supported in Java EE as long as it is running in a Java EE client container. The field/property in the main class must be static, though.

-Mike
 
Luciano A. Pozzo
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found an example that said: (JEE tutorial from Sun, the application is the lottery-annotation-client)

Here's an example of a plain Java client that runs outside of a Java EE container. In this case, it does a global JNDI lookup
since dependency injection is not available outside of a Java EE component.


So the example use InitialContext for lookup:




So is what Mike said above. But... what is Java EE client container?


And after I saw the security-stateless-appclient. That is a client that use @EJB annotation!




So... why example 1 cannot use annotation and the example 2 can? It's the Java EE client container?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic