Externalizing Application Properties
Configure your application using `application.properties` and `application.yml` files, and manage profiles.
Keep Config Flexible
Imagine building an app for different environments like development, testing, and production. Each might need unique database credentials, API keys, or server ports.
Hardcoding these values directly into your code is a bad practice. It makes your app inflexible and difficult to manage.
Externalizing configuration means storing these changeable values outside your main application code, allowing you to modify them without rebuilding your app.
application.properties
Spring Boot makes external configuration easy. The most common way is using the application.properties file, located in your src/main/resources folder.
It uses a simple key-value pair format, where each property is on a new line:
server.port=8080spring.datasource.url=jdbc:h2:mem:testdbmy.custom.greeting=Hello CoddyKit!
These values can then be injected into your Spring components.
All lessons in this course
- Understanding Spring IoC Container
- Dependency Injection in Practice
- Externalizing Application Properties
- Bean Scopes and Lifecycle Management