How to read properties file in spring boot
What you will learn here about spring boot
- How to read properties file in spring boot
How to read properties file in spring boot
Please follow the following steps to know how to read properties file in spring boot
1)First create a simple maven project
2)Please add web starter dependency in POM.xml:base
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
3)Please add properties in your application.properties
4)Please follow the following steps which is shown below
- Autowire Environment object
- Use getProperty() to get value from properties file
5)Now please run the spring boot application
6)Now please to browser and hit the url for getting name. You will see following kind of output in the browser
7)Now please to browser and hit the url for getting email. You will see following kind of output in the browser
Frequently Asked Question
1)How to read data from different properties file data?
Answer: Assume you have a test.properties file which is in resources folder. To read data from test.properties file just put @PropertySource(“classpath:test.properties”) on the top of your class and then use Environment object.