aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes NullPointer on Simple EJB injection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "NullPointer on Simple EJB injection" Watch "NullPointer on Simple EJB injection" New topic
Author

NullPointer on Simple EJB injection

Luciano A. Pozzo
Ranch Hand

Joined: Jun 20, 2005
Posts: 112
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
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10048
    
163

Please post the code and the exception stacktrace so that someone will be able to figure out what the problem is.


[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10048
    
163

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

Joined: Jun 20, 2005
Posts: 112
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
Marshal

Joined: Jul 20, 2005
Posts: 10048
    
163

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.
Sami Kosonen
Greenhorn

Joined: Sep 14, 2006
Posts: 13
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
Marshal

Joined: Jul 20, 2005
Posts: 10048
    
163

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

Joined: Sep 14, 2006
Posts: 13
Yes... I should have read the original posting again before answering.
[ November 08, 2006: Message edited by: Sami Kosonen ]
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
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


-Mike
Pro JPA 2: Mastering the Java Persistence API
Luciano A. Pozzo
Ranch Hand

Joined: Jun 20, 2005
Posts: 112
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointer on Simple EJB injection