简体   繁体   English

需要将String值中的枚举传递给Spring配置xml中的Map

[英]Need to pass enum in String value to Map in Spring config xml

I've an Enum class 我有一个Enum班

public enum MyEnum{
    ABC;
}

And i have this spring xml configuration. 我有这个春天的XML配置。

<util:map id="myMap">
    <entry key="ABC" value-ref="myObj" />
</util:map>

<bean id="mick" class="com.x.Mick">
    <property name="myMap" ref="myMap" />
</bean>

Above setup works fine and key to the map is passed as enum. 上面的设置工作正常,并且映射的键作为枚举传递。 But now my requirement is to pass the Key in String type from enum ie My map will look Map<String,String> instead of Map<MyEnum,String> 但是现在我的要求是从枚举中传递Key in String类型,即我的地图将看起来是Map<String,String>而不是Map<MyEnum,String>

Any suggestions on how to go about this? 关于如何进行此操作有什么建议吗?

Take a look at this post: Using Enum values as String literals 看一下这篇文章: 使用Enum值作为String文字

I guess that is just the Thing you want if i understand you correctly. 我想这就是您想要的,如果我正确理解您的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM