Announcement Announcement Module
Collapse
No announcement yet.
Struts 1.2.4 integrated with Spring 3.0.5 - Working without ContextLoaderPlugin Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Struts 1.2.4 integrated with Spring 3.0.5 - Working without ContextLoaderPlugin

    Hi all,

    We have a web application using EJB + Struts and currently doing a migration from EJB to Spring. We use the ContextLoaderPlugin to load all the spring context and use the DelegatingActionProxy to reference spring beans by matching the actions "path" to the spring beans "name".

    In a certain moment we found that we needed to migrate some EJBs that were being referenced from Servlets, so we needed to find a way to inject Spring beans into a Servlet since we don't have enough time to face a full servlet to struts action migration. We tried the SpringBeanAutowiringSupport approach, but found that all the spring context was being loaded with ContextLoaderPlugin, and no ContextLoaderListener was configured, what seems to be required for SpringBeanAutowiringSupport. As an initial approach to try to fix this issue we removed the ContextLoaderPlugin config and loaded all the spring context using ContextLoaderListener (configuring it in web.xml), and found that it works perfectly, the spring beans are injected into the servlets, the actions are being spring-managed and the component injection into actions is also working.

    Our question is, how is this possible? We can't find any reference stating that this should work, everywhere we find that a ContextLoaderPlugin is needed to do the match between struts actions in struts-config.xml and spring beans in our servlet.xml. Is what we did supposed to work and we are missing something? Is there any risk or reason why we shouldn't use this approach?

    Thanks for your time!
    Regards,
    Gato

    PS.: Currently using Spring 3.0.5 and Struts 1.2.4

  • #2
    Hey, did you find if there was something wrong by doing that?
    I actually tested it, and it works.
    I think it's related to the fact that we are using Spring 3, because if you go to the ContextLoaderPlugin class you will find that it has been deprecated since Spring 3. So maybe in this version it's not needed anymore, but I'm not sure.
    Thanks!

    Originally posted by gato View Post
    Hi all,

    We have a web application using EJB + Struts and currently doing a migration from EJB to Spring. We use the ContextLoaderPlugin to load all the spring context and use the DelegatingActionProxy to reference spring beans by matching the actions "path" to the spring beans "name".

    In a certain moment we found that we needed to migrate some EJBs that were being referenced from Servlets, so we needed to find a way to inject Spring beans into a Servlet since we don't have enough time to face a full servlet to struts action migration. We tried the SpringBeanAutowiringSupport approach, but found that all the spring context was being loaded with ContextLoaderPlugin, and no ContextLoaderListener was configured, what seems to be required for SpringBeanAutowiringSupport. As an initial approach to try to fix this issue we removed the ContextLoaderPlugin config and loaded all the spring context using ContextLoaderListener (configuring it in web.xml), and found that it works perfectly, the spring beans are injected into the servlets, the actions are being spring-managed and the component injection into actions is also working.

    Our question is, how is this possible? We can't find any reference stating that this should work, everywhere we find that a ContextLoaderPlugin is needed to do the match between struts actions in struts-config.xml and spring beans in our servlet.xml. Is what we did supposed to work and we are missing something? Is there any risk or reason why we shouldn't use this approach?

    Thanks for your time!
    Regards,
    Gato

    PS.: Currently using Spring 3.0.5 and Struts 1.2.4

    Comment


    • #3
      Originally posted by diegomtb View Post
      Hey, did you find if there was something wrong by doing that?
      I actually tested it, and it works.
      I think it's related to the fact that we are using Spring 3, because if you go to the ContextLoaderPlugin class you will find that it has been deprecated since Spring 3. So maybe in this version it's not needed anymore, but I'm not sure.
      Thanks!
      We fixed the issue almost 2 years ago, but I'm afraid I can't remember what was the change we made. We decided to follow a path backed up by the documentation - we load the Action's bean context using the ContextLoaderPlugin, and introduced some changes to load the Services using the ContextLoaderListener - which is the change I can't remember. For the servlets we created a superclass that uses the SpringBeanAutowiringSupport strategy.

      Are you having any issues with it, or you just need to make sure it won't blow on your face later?

      Gato

      Comment


      • #4
        Originally posted by gato View Post
        We fixed the issue almost 2 years ago, but I'm afraid I can't remember what was the change we made. We decided to follow a path backed up by the documentation - we load the Action's bean context using the ContextLoaderPlugin, and introduced some changes to load the Services using the ContextLoaderListener - which is the change I can't remember. For the servlets we created a superclass that uses the SpringBeanAutowiringSupport strategy.

        Are you having any issues with it, or you just need to make sure it won't blow on your face later?

        Gato
        I didn't find an issue so far. I just wanted to make sure that removing the ContextLoaderPlugin is safe.

        Comment

        Working...
        X