Announcement Announcement Module
Collapse
No announcement yet.
How can a Struts plugin get references to beans in Spring? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can a Struts plugin get references to beans in Spring?

    How can a Struts plugin get references to beans contained
    in a Spring context?

    I donít want to use any Spring-specific classes in this plugin.

    Any helps are appreciated.

  • #2
    Take a look at the source code of WebApplicationContextUtils and copy the getWebApplicationContext functionality to your plugin.

    Comment


    • #3
      Originally posted by Kees de Kooter
      Take a look at the source code of WebApplicationContextUtils and copy the getWebApplicationContext functionality to your plugin.
      Thanks for your reply.

      But I donít want to use any Spring-specific classes in this plugin.

      Comment


      • #4
        Not sure what you can do then

        You could abstract it with an interface:
        Code:
          interface BeanLoader {
            Object loadBean(final String name);
          }
        and then have one implementation which uses Spring etc.

        The only dependency in your structs action would be on the SpringBeanLoader, which is a single line.

        HTH.

        Comment


        • #5
          How can a Struts plugin get references to beans in Spring?

          Hi,

          Anyone has a better solution injecting bean in struts plugin without importing spring API.

          Thx
          Anan

          Comment


          • #6
            reference Struts <-> Spring beans

            Hi Anan,

            Generally one component will need to know about/ and be able to find the other, in order to set any reference between them.

            You can definitely achieve this; but it's not quite as easy as working solely in Spring. One bean/ action will be in Struts and hard to find from Spring; the other will be in Spring and hard to find from Struts.

            Order of initialization issues will also apply; it won't work if you try to set the reference at init-time, since one or the other side will still be uninited and nonexistent.


            Probably simplest: implement a static singleton class as a 'registry' which one side can set; and the other side can read later. This then decouples you from the Spring API, and from order-of-init issues.

            Any other solutions ?

            Cheers
            T

            Comment

            Working...
            X