• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency INjection through Annotations

 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have an EJB Module project which has:




And below is the web module:


But i am getting the bewlo exception:
Starting...
java.lang.NullPointerException
at com.stateless.DepInjHelloWorld.main(DepInjHelloWorld.java:19)


Line 19:System.out.println(hello.getMessage("Using Annotations Instead Of JNDI LookUp"));

PLease tell me if i need to configure anywhere,as i am not using any xml file.

Regards,
Amarshi
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not a web module; it is a main method. Are you running it as an application client or a regular Java class? If the later, you need to do a JNDI lookup and not dependency injection.
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also tried using a servlet instead of the standalone class, but the same exception comes.


---Amarshi
 
pulkit mehra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amrish,

Hope this help
This is Stand Alone Client for EJB 3.0 in JBoss :
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks pulkit, i have tried this way its working.
But i want to use dependency injection instead of jndi lookup.
I have googled a couple of examples (using dependency injection for jndi look up instead of using initial context for lookup), but for me the business interface instance comes as null.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You actually have 2 questions here.

1) Injection into standalone java clients - This isn't possible unless you use an application client container. See this previous discussion

2) Injection into servlets - This is allowed. If you are not able to inject into servlet, then see if the issue is related to this
 
pulkit mehra
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See..according to my experience dependency injection gets failed due to following reason :

1)You are using server which does not support DI in web container.eg JBoss 4.x(DI work in EJB not in WEB)
2)You must have giving wrong JNDI name.Please refer to JNDI console of your server and see naming convention they follow.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic