Video in progress
What are application.properties and application.yml used for?
Both keep configuration (port, database URL, log level, etc.) outside the code. The only difference is the syntax: properties is flat key=value, yml is hierarchical.
📖 Answer
The same configuration in two notations:
server.port=8081
spring.datasource.url=jdbc:postgresql://localhost:5432/shop
spring.datasource.username=shop
server:
port: 8081
spring:
datasource:
url: jdbc:postgresql://localhost:5432/shop
username: shop
Which one you pick is up to the team. Long keys are easier to read in YAML, but indentation mistakes happen often.
Things worth knowing:
- don't put passwords and keys in the file, let them come from the env:
password: ${DB_PASSWORD}; - profile-specific settings go into a separate file like
application-prod.yml; - if the same key is set in several places, env variables and command-line arguments win over the file.
Sign up to mark studied questions and save your progress.