Thursday, November 22, 2018

Spring Boot - Read yml file

When developing a Spring Boot application, we are using yml (properties) file to store the data. Due to this without we don't want to re-build the source code after change the property values.

Even thought this a very basic thing, in this article, I'm going to explain the way we can get the data from yml file.

For this explanation, I'm going to take application.yml file and we have a property as below
company:
  name: Company ABC

Then we can get this value in java code as below
public class TestApplication {
...
@Value("${company.name}")
        private String companyName;
...
}

This value will cast to the variable type.

Enjoy.....!!!

No comments:

Post a Comment