Results 1 to 2 of 2

Thread: When Spring does not create the 'root' object...

  1. #1
    Join Date
    Mar 2005
    Posts
    7

    Default When Spring does not create the 'root' object...

    If an object is created by some other infrastructure, it makes it impossible to use Spring to inject dependencies.

    For example, if I have class called Root which is automatically created by some other infrastructure and this class has a method setTrunk(), I cannot use Spring to call setTrunk because I cannot ask Spring to create Root (unless I can get access to Root after it's created using some singleton lookup I guess - but if I have to set it up as a singleton just for this purpose, it's not a clean design...).

    Another example, if I have a JUnit test case with a settor setDataSource(), how can I use Spring to call setDataSource() if I run the test case through JUnit?

    Is this problem statement accurate? If so, what are people doing to sidestep this problem in a clean way?



    Thanks,

    Ted

  2. #2
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default Re: When Spring does not create the 'root' object...

    Quote Originally Posted by anagnost68
    If an object is created by some other infrastructure, it makes it impossible to use Spring to inject dependencies.
    True.. if the object is complete, there is nothing left to inject/set. But it is possible to use that bean to inject in other beans.

    For example, if I have class called Root which is automatically created by some other infrastructure and this class has a method setTrunk(), I cannot use Spring to call setTrunk because I cannot ask Spring to create Root (unless I can get access to Root after it's created using some singleton lookup I guess - but if I have to set it up as a singleton just for this purpose, it's not a clean design...).
    You don`t have to set it up as a singleton. You could use another object with a static field for it and use the FieldRetrievingFactoryBean.

Similar Threads

  1. Replies: 12
    Last Post: Oct 30th, 2010, 12:26 AM
  2. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  3. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Replies: 3
    Last Post: Aug 30th, 2004, 09:56 AM

Posting Permissions

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