Spring Boot application.yml / application.yaml
1. Introduction
Spring Boot supports configuration using:
application.yml / application.yaml
YAML files are used to define configuration in a structured and readable format.
2. Why Use application.yml
Hierarchical structure
Easy to read
Less repetition
Better for large applications
Common in microservices
3. File Location
plaintext
src/main/resources4. Server Configuration
Change default port:
plaintext
server:
port: 89895. Application Name
plaintext
spring:
application:
name: my-app6. Database Configuration
MySQL Example
plaintext
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb
username: root
password: 1234
driver-class-name: com.mysql.cj.jdbc.DriverH2 Database Example
plaintext
spring:
datasource:
url: jdbc:h2:mem:testdb
username: sa
password: ""
h2:
console:
enabled: trueMongoDB Example
plaintext
spring:
data:
mongodb:
uri: mongodb://localhost:27017/mydb7. Eureka Server Configuration
plaintext
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
register-with-eureka: true
fetch-registry: true8. application.yml vs application.properties
Format
properties: key=value
yaml: hierarchical
Readability
properties: less readable for large config
yaml: more readable
Structure
properties: flat
yaml: nested
Usage
properties: simple configuration
yaml: complex configuration
9. Key Points
YAML uses indentation
No semicolons or brackets
Better for complex setups
Widely used in microservices
10. Conclusion
application.yml is modern and readable
Preferred for large applications
Helps organize configuration clearly