Where does Spring look for application.properties?
Spring Boot searches for application.properties in the following order (highest priority wins):

πΉ Override with CLI args:
java -jar myapp.jar --spring.config.location=file:/mydir/application.properties
How does Spring Boot load properties?
Spring Boot internally uses ConfigFileApplicationListener to load properties.
Key components:
-
ConfigFileApplicationListenerβ Detects and loadsapplication.properties -
PropertySourceLoaderβ Converts properties into key-value pairs -
YamlPropertySourceLoaderβ Handlesapplication.yml
πΉ Spring Boot loads properties like this:
new ConfigFileApplicationListener().addPropertySources(environment, resourceLoader);
What happens when a property is accessed?
When environment.getProperty("server.port") is called, Spring searches in this order:
1οΈβ£ Command-line arguments (--server.port=9090)
2οΈβ£ Environment variables (export SERVER_PORT=8081)
3οΈβ£ System properties (-Dserver.port=7070)
4οΈβ£ application.properties (server.port=6060)
5οΈβ£ Default value (server.port=8080)
πΉ Spring stops searching once a value is found!
How to debug property loading?
1οΈβ£ Enable debug logs:
java -jar myapp.jar --debug
2οΈβ£ Log property loading in application.properties:
logging.level.org.springframework.boot.context.config=DEBUG
What if application.properties is missing?
Spring Boot falls back to default values.
Top comments (0)