Results 1 to 6 of 6

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

  1. #1
    Join Date
    Jun 2005
    Posts
    9

    Default 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. #2
    Join Date
    Dec 2004
    Location
    Rotterdam, The Netherlands
    Posts
    162

    Default

    Take a look at the source code of WebApplicationContextUtils and copy the getWebApplicationContext functionality to your plugin.
    Kees de Kooter
    www.boplicity.net

  3. #3
    Join Date
    Jun 2005
    Posts
    9

    Default

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

  4. #4
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    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.

  5. #5
    Join Date
    Nov 2005
    Posts
    11

    Default 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

  6. #6
    Join Date
    Nov 2004
    Posts
    5

    Default 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

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

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