编程语言
首页 > 编程语言> > java – 我想读取具有贴图地图的spring属性文件

java – 我想读取具有贴图地图的spring属性文件

作者:互联网

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

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

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

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

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)

解决方法:

我找到了方法,我不得不删除’关键后’

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

以下代码选择它

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

标签:java,spring,spring-mvc,properties-file,config
来源: https://codeday.me/bug/20191003/1848248.html