0

I'm using springboot 2.6.14 in one of my project.

I can read simple strings from application.yml by using @Value notation.
But when I convert them to List or Map, I get error

Below works

// In applicaiton.yml --
a:
  b:
   c: abcd

// In a java class with @Component 
@Value("${a.b.c}")
String abc;

Below fails
with error Could not resolve placeholder 'a.b.c' in value "${a.b.c}"

 // In applicaiton.yml --
 a:
   b:
     c: 
      - abcd
      - efgh

  // In a java class with @Component 
  @Value("${a.b.c}")
     List<String> abcs;

What I tried

  1. I tried using SPEL expression @Value("#{${a.b.c}}"), but same exception.
  2. I explicitly imported org.yaml.snakeyaml dependency in the project, thought It might support. but same exception.
  3. I am not allowed to upgrade the springboot version in the project.

Any other solution ?

ThrowableException
  • 1,168
  • 1
  • 8
  • 29
  • 1
    `@Value` does not support mapping to complex types. Either use a comma separated value and SpEL to convert it to a list, or use `@ConfigurationProperties` as recommended in the duplicate. – g00glen00b Feb 01 '23 at 20:53

0 Answers0