Announcement Announcement Module
Collapse
No announcement yet.
Map values injection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Map values injection

    Hello
    I am having some issues related to binding entries to map property:

    Suppose I have several instances of classes implementing interface
    Code:
    interface MyInterface{
         int[] getPossibleMapKeys()
    }
    for example:
    Code:
    @Component
    public class ClassA{
         int[] getPossibleMapKeys(){
         return new int[2] // suppose we have some values
        }
    }
    and I have another class C like
    Code:
    @Component
    class ClassHavingMap{
         @Autowired
         private Map<Integer, MyInterface> myMap;
    }
    and I want to define in xml that all my instances of MyInterface class would be autowired to myMap property:
    Code:
        <bean class="ClassHavingMap">
    
            <property name="myMap">
                <map>
                    <entry key="???" value-ref="???"/>
               </map>
    ...
    How can i assure that the same instance of MyInterface class will be stored under all different map keys, returned by getPossibleMapKeys() method? Do you know if it is even possible or it is totally wrong approach?
Working...
X