[英]Spring Beans - wiring class as key and value to map
How would one wire key/value pairs into a property like this ? 一个线键/值对如何变成这样的属性?
private Map<Class<? extends ObjectOne>, Class<? extends ObjectTwo>> classes;
Both ObjectOne and ObjectTwo are abstract if that is of any help. 如果有帮助的话,ObjectOne和ObjectTwo都是抽象的。
you can probably define the bean in appcontext as 您可能可以在appcontext中将bean定义为
<bean id="id" class = "pathtoyourclass">
<property name="propname">
<map>
<entry key-ref="id of class extends objectone's bean" value-ref="id of class extends objecttwo's bean">
</map>
</property>
</bean>
As this stackoverflow post has bit confused me it seems that there is nothing to it wiring map like I declared. 由于这个stackoverflow帖子使我有些困惑,似乎没有什么像我声明的那样连接图了。
<map>
<entry key="org.sandbox.ObjectOneExt"
value="org.sandbox.ObjectTwoExt" />
<!-- where ObjectOneExt and ObjectTwoExt are extended from ObjectOne and ObjectTwo respectively -->
</map>
Spring (at least 3.1) handled this the way I wanted. Spring(至少3.1)按照我想要的方式进行了处理。 So all that is required is to specify full class path to an object in key and value.
因此,所需要做的就是用键和值指定对象的完整类路径。 The "key-type="java.lang.Class"" which is demonstrated in post somehow made spring confused but once removed worked like a charm.
文章中演示的“ key-type =“ java.lang.Class””使spring感到困惑,但是一旦删除,它就像一个魅力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.