Results 1 to 3 of 3

Thread: DI in my struts plugin

  1. #1
    Join Date
    May 2006
    Posts
    4

    Default DI in my struts plugin

    Hello,

    I'm using Struts 1.2 & have developed a plugin for my application which stores some objects in application scope.

    These objects are fetched from database (DAO pattern) by using the service layer.

    Now, I want to inject the service object into my struts plugin. Since, Spring (1.2) does not instantiate the struts plugin it can not do DI into it.

    Is there a work around for this problem?

    Thanks,

    Hashir Ahmed

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Ahamd,

    you may implement DI the pullway:

    the following code, from org.springframework.web.struts.ActionSupport, shows how to access the WebApplicationContext from a struts Action / Plugin:

    Code:
        /**
         * Fetch ContextLoaderPlugIn's WebApplicationContext from the ServletContext,
         * falling back to the root WebApplicationContext (the usual case).
         * @param actionServlet the associated ActionServlet
         * @return the WebApplicationContext
         * @throws IllegalStateException if no WebApplicationContext could be found
         * @see DelegatingActionUtils#findRequiredWebApplicationContext
         */
        protected WebApplicationContext initWebApplicationContext(ActionServlet actionServlet)
                throws IllegalStateException {
    
            return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet, null);
        }
    HTH.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    May 2006
    Posts
    4

    Default Thanks

    Thanks irbouho,

    It solved my problem.

    Keep up the good work.

    Hashir Ahmed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •