File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Dependency 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 "Dependency Injection" Watch "Dependency Injection" New topic

Dependency Injection

Brian Stegen

Joined: Dec 04, 2009
Posts: 2
I'm new to the EJB 3.0 concept. I've created a simple hello world session bean and the bean is running in my container. I've successfully created a client to access the bean using context lookup method (JNDI). When I attempt to create another client to access using DI, I receive a null pointer exception and not sure why.

private static HelloWorld helloWorld;

public static void main(String[] args) {

Thanks in advance for the assistance!
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489


What kind of IDE you use?..
do you use Eclipse or Netbeans?..
if you use Netbeans you would be asked about the EJB Client application..
(its mean that your application will deployed also into server)..

@EJB Annotation is only could be used in Container Managed class..
and you could run the code successfully if your application had been deployed..

Hope that helps..

Please correct me if i'm wrong..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

To add to what Leonardo mentioned, injection in standalone java classes is not supported. However, standalone java classes can be run as "application clients". Application clients do support injection (they have their own set of rules). Each application server, has its own way of running application clients. Which application server (and which version) are you using?

[My Blog] [JavaRanch Journal]
Brian Stegen

Joined: Dec 04, 2009
Posts: 2
I'm using JDeveloper an Eclispe based IDE. Attempting to use the embedded server for testing. Now trying to figure out how to run my java class as an application client in the embbedded server.
I agree. Here's the link:
subject: Dependency Injection
It's not a secret anymore!