Announcement Announcement Module
Collapse
No announcement yet.
DI in my struts plugin Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      Thanks

      Thanks irbouho,

      It solved my problem.

      Keep up the good work.

      Hashir Ahmed

      Comment

      Working...
      X