Author
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.
Spring Boot uses configuration files to define application settings, database connections, logging levels, and environment-specific properties.
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:
spring.datasource.url)server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/mydb
username: root
password: secret
logging:
level:
org.springframework: INFONotes:
| 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:
application.properties for simple projectsapplication.yml for nested or complex configurationsSpring 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’s MessageSource reads these for multi-language support.logback-spring.xml / logback.xml → Optional configuration for Logback logging in development or production environments.static/, public/, and META-INF/resources/ are for static content (CSS, JS, images).templates/ is for dynamic views.user/, admin/) for better maintainability..properties / .yml) define app settings, database connections, logging, and environment-specific configs.static/, templates/, db/, messages.properties) store static content, dynamic views, SQL scripts, and i18n messages.