복붙노트

[SPRING] 나는지도의지도가있는 봄 속성 파일을 읽고 싶다.

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)

해결법

  1. ==============================

    1.나는 길을 발견했다, 나는 단지 열쇠를 제거해야했다.

    나는 길을 발견했다, 나는 단지 열쇠를 제거해야했다.

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

    코드 아래에 그것을 집어 넣는다.

    @Value("#{${propertymap}}")  
    private Map<String,Map<String,String>> propertymap;
    
  2. from https://stackoverflow.com/questions/47272477/i-want-to-read-spring-properties-file-that-has-a-map-of-maps by cc-by-sa and MIT license