Aja*_*man 3 java spring config spring-mvc properties-file
我想要一个像下面这样的属性,它是地图
propertymap = {
key1:'{subkey1:'subvalue1',subkey2:'subvalue2'}',
key2:'{subkey3:'subvalue3',subkey4:'subvalue4'}' }
@Value("#{${propertymap}}")
private Map<String,Map<String,String>> propertymap;
Run Code Online (Sandbox Code Playgroud)
在我的配置类中使用了类似上面的代码,但出现错误。请让我知道是否有办法做到这一点。
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)
Run Code Online (Sandbox Code Playgroud)
我找到了方法,我只需要删除键后的 '
propertymap = {
key1:{
subkey1:'subvalue1',
subkey2:'subvalue2'
},
key2:{
subkey3:'subvalue3',
subkey4:'subvalue4'
}
}
Run Code Online (Sandbox Code Playgroud)
和下面的代码把它捡起来
@Value("#{${propertymap}}")
private Map<String,Map<String,String>> propertymap;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1596 次 |
最近记录: |