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

Dependency Injection

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
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
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic