Specifing the keys of a map when autowiring in spring
<p>Can I specify for spring how to set the key of a map when it is autowired?</p>

<p>In the following example I would like to somehow let spring know that the returned value of the beans' getKey() should act as key for the autowired map of the mapHolder bean.</p>

<pre><code>public interface MyInterface{
    int getKey();
}

@Component
public ImplA implements MyInterface{
    @Override
    public int getKey(){
        return 1;
    }
}

@Component
public ImplB implements MyInterface{
    @Override
    public int getKey(){
        return 2;
    }
}

@Component
public MapHolder{
    @Autowire
    private Map&lt;Integer, MyInterface&gt; myAutowiredMap;

    public mapHolder(){
    }
}


&lt;context:component-scan base-package="com.myquestion"&gt;
    &lt;context:include-filter type="assignable" expression="com.myquestion.MyInterface"/&gt;
&lt;/context:component-scan&gt;

&lt;bean id="mapHolder" class="com.myquestion.MapHolder"/&gt;
</code></pre>