Force Spring Yaml configuration environment parameter to be treated as yaml instead of String

Intro: I have a Spring Boot application with its configuration set up with application.yml file like so: - Scala class:
@ConfigurationProperties(prefix = "foo.bar")
@ConstructorBinding
case class MyConfig(
biz: String,
testYamlMaps: java.util.Map[String, String]
)
@ConfigurationProperties(prefix = "foo.bar")
@ConstructorBinding
case class MyConfig(
biz: String,
testYamlMaps: java.util.Map[String, String]
)
- application.yml:
foo:
bar:
biz: "hello"
test-yaml-maps: ${YAML_TEST_MAP} # option 1
# test-yaml-maps: {redelivery: true, secure: false} option 2
foo:
bar:
biz: "hello"
test-yaml-maps: ${YAML_TEST_MAP} # option 1
# test-yaml-maps: {redelivery: true, secure: false} option 2
- YAML_TEST_MAP environment variable:
$ echo $YAML_TEST_MAP
{redelivery: true, secure: false}
$ echo $YAML_TEST_MAP
{redelivery: true, secure: false}
Problem: Option 2 works but with option 1 it looks like Spring is parsing application.yml first and only then substitutes environment values this way treating YAML_TEST_MAP as a String making it throw this error:
No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]
No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]
Question: Is there a way to force Spring replace environment variables first and only then parse? Is there a way to tell Spring to treat value as a rest of yaml document?
4 Replies
JavaBot
JavaBot•3y ago
Hey, @Lil Villa! Please remember to /close this post once your question has been answered!
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Lil Villa
Lil VillaOP•3y ago
Thank you for an answer :prayge:
JavaBot
JavaBot•3y ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.

Did you find this page helpful?