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

后端 未结 7 544
有刺的猬
有刺的猬 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:48

    You just need to use concrete Map class as HashMap and not abstract or interface:

    public class Mick {
    
      private HashMap<MyEnum, OtherObj> myMap;
    
      @Autowired
      public void setMyMap(HashMap<MyEnum, OtherObj> myMap) {
        this.myMap = myMap;
      }
    }
    
    
    public class AppConfig
    {
        @Bean
        public HashMap<MyEnum, OtherObj> myMap() { .. }
    }
    
    0 讨论(0)
提交回复
热议问题