struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wes Wannemacher <>
Subject Re: [QUESTION]
Date Sun, 22 Feb 2009 04:07:05 GMT
On Saturday 21 February 2009 22:44:28 Karan Malhi wrote:
> Hi,
> I work on the OpenEJB project. I wanted to add support for injecting
> resources into struts actions i.e. if somebody creates a struts based web
> app and deploys it in Tomcat + OpenEJB, then I want the user to be able to
> annotate the struts actions with @EJB, @Resource etc and then have OpenEJB
> inject those resources. To do that, I need to find out which classes in the
> web-app represent actions. Initially I thought that struts.xml would
> contain all the Action classes (listed as part of action elements).  Then I
> found out that one could also include other xml files within struts xml
> using the <include/> element. Since I do not know struts 2 that well, I
> have a few questions which will help me a long way to add injection
> support:- 1. Does the struts config files has to be named struts.xml or can
> it be named something else? If yes, how would struts discover such a file?
> 2. Are all actions mapped in struts.xml and the included xml files (using
> the include element) or there could be actions which do not need to be
> listed in these xml files.

There are likely to be actions mapped via other means. There are many plugins 
available, most prominently the REST plugin and the Convention plugin that 
allow our users to map actions without any XML

> 3. I was planning to write a plugin, but wanted to have access to the
> ServletContext within the plugin. Could you show me how to do that -- I
> tried implementing ServletContextAware in the plugin class, but that did
> not work for me (maybe that interface is only supposed to be implemented by
> actions)

That interface is meant for actions. The best way to get a ServletContext is 
to do the following from an interceptor - 

final ActionContext context = invocation.getInvocationContext();
ServletContext servletContext = (ServletContext)    

You may face a few issues though. I've thought briefly about EJB + Struts2 
lately and I'll admit to a lack of experience with EJB, but it seems to me 
that it would be somewhat difficult to combine the two easily. Many of the EJB 
annotations can appear on private members (i.e. @PersistenceContext). In 
Struts2, we create actions via our own ObjectFactory, which can be overridden 
by a plugin. 

There are at least two plugins available that provide EJB integration, but 
they go about it by introducing a new annotation that are then checked for in 
an interceptor with EJBs injected when the annotation is found ->

I'm not particularly familiar with OpenEJB, but I'd like to help however I 
can. So, let me know if you need the help.


Wes Wannemacher
Author - Struts 2 In Practice 
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message