Properties files are used to keep ‘N’ number of properties in a single file to run the application in a different environment. In Spring Boot, properties are kept in the application.properties file under the classpath.
Spring Boot provides various properties that can be configured in the application.properties file. The properties have default values. We can set a property(s) for the Spring Boot application. Spring Boot also allows us to define our own property if required.
The application.properties file allows us to run an application in a different environment. In short, we can use the application.properties file to:
- Configure the Spring Boot framework
- define our application custom configuration properties
Spring Boot application.properties example file
#configuring application name
spring.application.name = demoApplication
server.port = 8081
In the above example, we have configured the application name and port. The port 8081 denotes that the application runs on port 8081.
Spring Boot supports YAML based properties configurations to run the application. Instead of application.properties, we can use application.yml file. This YAML file also should be kept inside the classpath. The sample application.yml file is given below −