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 Struts 2 EJB 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 "Struts 2 EJB injection" Watch "Struts 2 EJB injection" New topic

Struts 2 EJB injection

Prateek Jauhari

Joined: Mar 07, 2011
Posts: 26

Is It possible to inject a stateless session bean using @EJB annotation in a Struts 2 Action class.

Each time a execute my action class, I recieve a null pointer exception.

Is EJB injection possible in Struts 2 action class.

Is there any tutorial or link for this.


Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

What version of JEE are you asking for? In JEE 5, you can only inject into JSF resources, servlets, etc. In JEE 6, things are more flexible. This thread explains it nicely.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Prateek Jauhari

Joined: Mar 07, 2011
Posts: 26

Thanks this link really solved my problem..
but I am now facing another one, The hibernate is not working in it now..
I am using JEE 6, hibernate 3.5, struts 2 and EJB3.0 with JBoss 6 application server and MySQL.
for my project.

IS there any tutorial to integrate all these into a single project.
I really fed working out with this


Prateek Jauhari

Joined: Mar 07, 2011
Posts: 26

I am really thankful.
This link solved my problem...
but I didn't understand why this thing is not working with struts application.
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 808

Am I right that JBoss Weld can be used to inject EJB into struts action:
@Inject ?

I agree. Here's the link:
subject: Struts 2 EJB injection
It's not a secret anymore!