Announcement Announcement Module
No announcement yet.
Setter injection and map keys Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setter injection and map keys

    I ran into a a dependency problem in a Spring 1.2.7 application whereby one object is created via setter injection. Lets call this object1. The hashCode method for object1 uses a value injected via Spring.

    Elsewhere in my Spring context definition, I have injected a map into another object, where one of the keys of this map is a key-ref to object1.

    Using that injected map, containsKey(object1) == false. Using a debugger, I determined the reason for this is that the hashCode of the object in the map is based on object1.hashCode() *before* Spring called the object1 setter. Adding depends-on to the bean containing the map has no effect.

    Unfortunately, I am unable to (so far) replicate this in a simple test case -- but it occurs consistently in my application. What are the possible reasons the dependencies are not being handled in my app?

    Raman Gupta

  • #2
    Circular references

    Based on the debug logs, I can see this has something to do with delayed initialization due to circular references. For some reason though, I am still unable to replicate this in a simple test case...

    Are their any work-arounds other than using contructor injection for the property that needs to be initialized up-front? Why wouldn't Spring initialize the object with as much state as possible, despite the circular references (the property in question is just a String)?