Spring Boot: Load @Value from YAML file

We Are Going To Discuss About Spring Boot: Load @Value from YAML file. So lets Start this Java Article.

Spring Boot: Load @Value from YAML file

  1. Spring Boot: Load @Value from YAML file

    M. Deinum is right, the setup i've provided is working – the yml file was indented wrong, so the property couldn't be found.

  2. Spring Boot: Load @Value from YAML file

    M. Deinum is right, the setup i've provided is working – the yml file was indented wrong, so the property couldn't be found.

Solution 1

For example: application.yml

key:
 name: description here

Your Class:

@Value("${key.name}")
private String abc;

Original Author Nick Borges Of This Content

Solution 2

M. Deinum is right, the setup i’ve provided is working – the yml file was indented wrong, so the property couldn’t be found.

Original Author Nick Borges Of This Content

Solution 3

I found the above wasn’t working for me, because I tried to access the variable in a constructor. But at construction, the value is not injected yet.
Eventually I got it to work using this workaround: https://mrhaki.blogspot.com/2015/04/spring-sweets-using-value-for.html

Maybe this is helpful to others.

Original Author Kjeld Of This Content

Solution 4

For me a duplicate key in the property file caused this…

I used same key unknowingly in large yml file.

key:   
 key1: value
 key2: value

key:  
 key3: value

Original Author SatyaRajC Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment