Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency Injection

 
Brian Stegen
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!");
}

Thanks in advance for the assistance!
Brian
 
Leonardo Carreira
Ranch Hand
Posts: 489
Eclipse IDE Java Postgres Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

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..
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Brian Stegen
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic