我想阅读具有地图地图的spring属性文件 [英] I want to read spring properties file that has a map of maps

查看:255
本文介绍了我想阅读具有地图地图的spring属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个像下面这样的地图,这是一张地图地图

I want to have a property like below that is a map of maps

propertymap = {
    key1:'{subkey1:'subvalue1',subkey2:'subvalue2'}',
    key2:'{subkey3:'subvalue3',subkey4:'subvalue4'}' }

@Value("#{${propertymap}}")  
private Map<String,Map<String,String>> propertymap;

在我的配置类中使用了类似上面的代码但是出错了。如果有办法,请告诉我。

used code like above in my config class but got error. please let me know if there is a way to do this.

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.util.Map  nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelParseException: EL1043E:(pos 17): Unexpected token. Expected 'rcurly(})' but was 'identifier'
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)


推荐答案

我找到了方法,我不得不删除'后面的键'

I found the way, I had to just remove the ' after the key

propertymap = {  
   key1:{  
      subkey1:'subvalue1',
      subkey2:'subvalue2'
   },
   key2:{  
      subkey3:'subvalue3',
      subkey4:'subvalue4'
   }
}

以下代码选择

@Value("#{${propertymap}}")  
private Map<String,Map<String,String>> propertymap;

这篇关于我想阅读具有地图地图的spring属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆