Sitemap
JavaGuides

Guides on Java, Spring Boot, REST APIs, Full-Stack Web development, Microservices, Cloud, Databases, and tools with hands-on tutorials and best practices.

Member-only story

Spring Boot Profiles: How to Manage Environment-Based Configurations

3 min readMar 3, 2025

--

This is a member-only article. For non-members, read this article for free on my blog: Spring Boot Profiles.

๐Ÿš€ Introduction to Spring Boot Profiles

Spring Boot Profiles allow applications to load different configurations based on the environment (e.g., development, testing, production).

โœ… Why Use Spring Boot Profiles?
โœ” Manage Environment-Specific Settings (Database, API Keys, Logging).
โœ” Easily Switch Configurations without modifying code.
โœ” Use Different Beans for Different Environments (@Profile).
โœ” Avoid Hardcoding Environment Variables.

๐Ÿ“Œ In this guide, youโ€™ll learn:
โœ… How Spring Boot Profiles Work.
โœ… Using application.properties and application.yml for Profiles.
โœ… How to Load Beans Conditionally Using @Profile.
โœ… How to Switch Between Profiles.

1๏ธโƒฃ How Do Spring Boot Profiles Work?

Spring Boot Profiles allow you to define multiple environment-specific configurations and activate them dynamically.

๐Ÿ“Œ Common Profiles Used in Projects:

2๏ธโƒฃ Defining Profiles in application.properties

By default, Spring Boot loads application.properties, but we can create environment-specific files like:

application-dev.properties  
application-test.properties
application-prod.properties

๐Ÿ“Œ Example: application-dev.properties (Development Settings)

server.port=8081
spring.datasource.url=jdbc:h2:mem:devdb
logging.level.root=DEBUG

๐Ÿ“Œ Example: application-prod.properties (Production Settings)

--

--

JavaGuides
JavaGuides

Published in JavaGuides

Guides on Java, Spring Boot, REST APIs, Full-Stack Web development, Microservices, Cloud, Databases, and tools with hands-on tutorials and best practices.

No responses yet