Spring Boot Configuration Files & Key Resource Folders
In Spring Boot, the src/main/resources folder holds all non-Java resources such as configuration files, static assets, templates, SQL scripts, and internationalization (i18n) messages. These resources are auto-detected and served by Spring Boot, supporting a modular, maintainable, and production-ready project structure.
This guide explains configuration files (application.properties / application.yml) and the key resource folders you should know in a Spring Boot project.
1. Configuration Files: application.properties vs application.yml
Spring Boot uses configuration files to define application settings, database connections, logging levels, and environment-specific properties.
a) application.properties
- Format: Key-value pairs (flat structure)
- Usage: Best for simple to medium projects
Example:
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=secret
logging.level.org.springframework=INFO
Notes:
- Hierarchies are expressed using dots (e.g.,
spring.datasource.url) - Each property is on a single line
b) application.yml
- Format: YAML (structured, hierarchical)
- Usage: Ideal for complex applications with nested settings or multiple profiles
- Example:
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb
username: root
password: secret
logging:
level:
org.springframework: INFONotes:
- Easier to read for nested configurations
- Supports lists, maps, and multi-line values
- Ideal for profile-specific configurations (dev, prod, test)
Key Differences
| Feature | application.properties | application.yml |
|---|---|---|
| Format | Key-value | YAML (hierarchical) |
| Readability | Simple, flat | Clear for nested structures |
| Complexity Handling | Not ideal for deep hierarchies | Handles complex/nested config easily |
| Lists/Maps | Limited / comma-separated | Natural support for lists/maps |
| Profile-Specific Config | application-{profile}.properties | application-{profile}.yml |
| Learning Curve | Easier for beginners | Slightly higher, more flexible |
Best Practices:
- Use
application.propertiesfor simple projects - Use
application.ymlfor nested or complex configurations - Use profile-specific files for different environments
- Avoid mixing formats unless necessary
2. Key Resource Folders in src/main/resources
Spring Boot automatically detects and serves these folders without extra configuration:
application.properties / application.ymlβ Central configuration (database, server, logging, external services)static/β Static frontend assets (CSS, JS, images, fonts). Automatically served at root URLs.public/β Alternative location for static files. Useful for packaged JARs or library assets.META-INF/resources/β Another static resource location, mainly for libraries or dependencies.templates/β Dynamic HTML templates rendered by view engines like Thymeleaf, JSP, or FreeMarker. Controllers return template names, which Spring resolves automatically.db/β Optional folder for SQL scripts or database initialization files (e.g.,schema.sql,data.sql).messages.propertiesβ Resource bundles for internationalization (i18n). SpringβsMessageSourcereads these for multi-language support.logback-spring.xml / logback.xmlβ Optional configuration for Logback logging in development or production environments.
Notes on Static & Template Folders
static/,public/, andMETA-INF/resources/are for static content (CSS, JS, images).templates/is for dynamic views.- Organize static files and templates into subfolders (e.g.,
user/,admin/) for better maintainability.
Conclusion
- Configuration files (
.properties/.yml) define app settings, database connections, logging, and environment-specific configs. - Resource folders (
static/,templates/,db/,messages.properties) store static content, dynamic views, SQL scripts, and i18n messages. - Proper usage ensures clean separation of concerns, modular design, and easy maintainability, following Spring Boot best practices for 2025.
