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.
@EJB
private static HelloWorld helloWorld;
public static void main(String[] args) {
helloWorld.sayHello("Beginner!");
}
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..
Thanks..
Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
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?
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 have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad: