1

given the following sample class

@ConfigurationProperties("myapp")
public class MyProps {

    MyProps(Map<String, String> propertymap) {
        System.out.println("propertymap = " + propertymap);
    }
}

and following application.yml

myapp:
  propertymap:
    a: b
    c: d

Everything works fine.

Now I try to do property resolving with the propertymap in my yaml and I wonder whether spring boot supports that? I change the yaml file to the following:

somecloud:
  someprefix:
    propertymap:
      a: b
      b: c

myapp:
  propertymap:
    ${somecloud.someprefix.propertymap}

The application start fails with:

Failed to bind properties under 'myapp.propertymap' to java.util.Map<java.lang.String, java.lang.String>:

    Property: myapp.propertymap
    Value: "${somecloud.someprefix.propertymap}"
    Origin: class path resource [application.yml] - 9:5
    Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]

Basically, I try to resolve the property which normale works like a gem, but in this case the property itself is a map. Does spring boot support "map property resolving" in any way and am I doing it wrong? Or is it simply not supported?

Background: I am working in a cloud environment (Cloud Foundy) and the properties are given from the outside. The properties will be prefixed with some cloud stuff (vcap.services) which I want to "rewrite" in my application. Yes, I could use the cloud prefix ("vcap.services....") directly in my application code, but that would make my application less portable which I want to prevent.

Any ideas?

markus_
  • 480
  • 3
  • 12
  • Yes, it should work. Do you have explicit libraries for yaml parsing? – dcolazin Jul 31 '23 at 07:43
  • first of all, why do you need structure like this ? – muhammed ozbilici Jul 31 '23 at 07:44
  • Thanks for your reply! @dcolazin I use only plain spring boot – markus_ Jul 31 '23 at 08:20
  • Thanks for your reply! @muhammedozbilici which structures do you mean, binding a map with configuration properties is state of the art spring boot – markus_ Jul 31 '23 at 08:20
  • *somecloud.someprefix.propertymap* will NOT return everytything underneeth it as you would expect (rather empty value). You can test this checking what will be bound t o `@Value(${somecloud.someprefix.propertymap})` – Antoniossss Jul 31 '23 at 09:08
  • Thank you, yes, I know that and you exactly understood the problem. But do you also have any solutions how one could resolve a map and not only the empty string? – markus_ Jul 31 '23 at 09:15

0 Answers0