The difference is that the container did not instantiate your struts
action, struts did. There are EJB plugins available, check the plugin
registry.

http://cwiki.apache.org/S2PLUGINS/home.html

The ones I have seen are based on injection via interceptor. I've
toyed with the notion of creating an ObjectFactory based plugin so
that struts can delegate creation of action classes to the ejb
container. This would allow for injection for more than just @EJB
(@PersistenceContext comes to mind).

The only issue is that it doesn't seem like we see much traffic on
here from ejb users. Would anyone else be interested in an
ObjectFactory based plugin? If so, would any of you also want it to
work with Spring? The interceptor-based solution works good because it
doesn't interfere with object-creation-based plugins like
spring/guice/etc.

-Wes

On Wed, Jul 15, 2009 at 9:21 AM, Robin Mannering<ro...@mtndesigns.co.uk> wrote:
> Hello,
>
> Platform : Struts 2, EJB 3.0, Glassfish 2.1
>
> I wish to obtain a reference to an EJB using injection.
>
> This works fine within a servlet, but from within a Struts2 action class,
> all references to injected EJB variables hold a 'null' reference.
>
> I've included a portion of my action class below.
>
> I'm confused as to why a Servlet has no trouble using injection as compared
> to the Struts 2 action class.  Both the servlet and action class reside in
> the same Web application.
>
> Does anybody have any ideas?
>
> /public class UserAction extends ActionSupport implements
> ServletRequestAware, SessionAware {
>
>   private static Logger logger = Logger.getLogger(SetupServlet.class);
>     @EJB
>   SetupServiceBeanLocal setupService;
>     @EJB
>   UserServiceBeanLocal userService;
> ...
> }/
>



-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to