Spring - How do you set Enum keys in a Map with annotations

后端 未结 7 569
有刺的猬
有刺的猬 2020-12-13 09:08

I\'ve an Enum class

public enum MyEnum{
    ABC;
}

than my \'Mick\' class has this property

private Map

        
7条回答
  •  醉酒成梦
    2020-12-13 09:36

    The element has key-type, resp. value-type attributes, that represents the class of the keys, resp. the values. If you specify the fully qualified class of your enum in the key-type attribute, the keys are then parsed into that enum when creating the map.

    Spring verifies during injection that the map's key and value types -as declared in the class containing the map- are assignment-compatible with the key and value types of the map bean. This is actually where you get the exception from.

提交回复
热议问题