← Back to Questions
Spring Boot

What is profile in Spring Boot?

Learn What is profile in Spring Boot? with simple explanations, real-time examples, interview tips and practical use cases.

What is Profile in Spring Boot?

A Profile in Spring Boot is a mechanism used to manage environment-specific configurations and beans for different application environments such as:

  • Development (dev)
  • Testing (test)
  • Staging (stage)
  • Production (prod)

Profiles allow Spring Boot applications to behave differently based on the active environment without changing the source code.

In simple terms:

  • Profiles separate environment configurations
  • Different environments use different settings
  • Spring Boot loads only the active profile configuration
  • Applications become flexible and production-ready

Spring Profiles are heavily used in:

  • Spring Framework
  • Spring Boot
  • Microservices Architecture
  • Cloud-Native Systems
  • Enterprise Applications

Simple Definition

A Profile in Spring Boot is used to load different configurations and beans for different environments.


Why Profiles are Important

Enterprise applications usually run in multiple environments:

  • Local Development
  • Testing Environment
  • UAT Environment
  • Production Environment

Each environment requires different:

  • Database URLs
  • API endpoints
  • Security configurations
  • Logging levels
  • External service configurations

Profiles help manage these differences cleanly.


Real-Time Banking Example

Consider a banking application.

Development Environment

  • Uses local MySQL database
  • Debug logging enabled
  • Mock payment gateway

Production Environment

  • Uses production database cluster
  • Error logging only
  • Real payment gateway

Spring Profiles allow switching between these environments easily.


How Profiles Work Internally

Application Starts
      |
Active Profile Identified
      |
Spring Loads Matching Configuration
      |
Environment-Specific Beans Created
      |
Application Ready
    

Default Configuration File

Spring Boot uses:

application.properties
    

or

application.yml
    

Profile-Specific Configuration Files

Spring Boot supports:

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

Development Profile Example

application-dev.properties

server.port=8080

spring.datasource.url=
jdbc:mysql://localhost:3306/dev_db

logging.level.root=DEBUG
    

Production Profile Example

application-prod.properties

server.port=9090

spring.datasource.url=
jdbc:mysql://prod-db:3306/prod_db

logging.level.root=ERROR
    

Activating a Profile

Profiles can be activated using:

spring.profiles.active
    

Example

spring.profiles.active=dev
    

Spring Boot loads:

application-dev.properties
    

Activating Profiles Using Command Line

java -jar app.jar
--spring.profiles.active=prod
    

Activating Profiles Using Environment Variables

SPRING_PROFILES_ACTIVE=prod
    

Using @Profile Annotation

Spring allows environment-specific bean creation using:

@Profile
    

Development Bean Example

@Service
@Profile("dev")
public class MockPaymentService
implements PaymentService {

}
    

Production Bean Example

@Service
@Profile("prod")
public class RealPaymentService
implements PaymentService {

}
    

Spring loads only the matching bean for the active profile.


Multiple Profiles Example

@Profile({"dev", "test"})
@Service
public class TestNotificationService {

}
    

Bean loads for:

  • dev
  • test

Default Profile in Spring Boot

If no profile is specified:

  • Spring Boot uses the default profile

Default configuration:

application.properties
    

Profile Precedence

Spring Boot loads configurations in this order:

  1. Command-line arguments
  2. Environment variables
  3. application-profile.properties
  4. application.properties

Using Profiles with YAML

application.yml

spring:
  profiles:
    active: dev
    

Profile-Specific YAML Example

application-dev.yml

server:
  port: 8080

logging:
  level:
    root: DEBUG
    

Using Profiles in @Configuration Classes

@Configuration
@Profile("prod")
public class ProductionConfig {

}
    

Configuration loads only in production environment.


Using Profiles in Microservices

Modern microservices architectures heavily rely on profiles because:

  • Each environment requires different configurations
  • Cloud deployments are dynamic
  • Security settings differ across environments
  • Distributed systems need flexibility

Microservices Banking Example

Development Environment

service.payment.url=
http://localhost:8081
    

Production Environment

service.payment.url=
https://payment.bank.com
    

Profiles automatically switch service URLs.


Advantages of Profiles

  • Environment-specific configuration
  • Better maintainability
  • Improved deployment flexibility
  • Cleaner configuration management
  • Supports cloud-native architecture

1. Environment Isolation

Each environment uses separate configuration settings.


2. Better Security

Production secrets remain separate from development configurations.


3. Easier Deployment

Applications can switch environments without code changes.


4. Better Scalability

Profiles support enterprise and cloud-native deployments efficiently.


Disadvantages of Profiles

  • Large numbers of profiles increase complexity
  • Configuration duplication may occur
  • Improper profile management can create deployment issues

Profiles vs Hardcoded Configuration

Feature Profiles Hardcoded Configuration
Environment Flexibility High Low
Deployment Simplicity Easy Difficult
Maintainability Better Poor
Scalability Enterprise Ready Limited

Profiles in Spring Boot Cloud

Spring Cloud frequently combines profiles with:

  • Config Server
  • Kubernetes
  • Docker
  • AWS
  • Azure

Docker Example

docker run
-e SPRING_PROFILES_ACTIVE=prod
banking-app
    

Kubernetes Example

env:
  - name: SPRING_PROFILES_ACTIVE
    value: prod
    

Common Spring Annotations Related to Profiles

  • @Profile
  • @Configuration
  • @Value
  • @ConfigurationProperties
  • @Bean

Real-World Enterprise Use Cases

  • Banking systems
  • Payment gateways
  • Cloud-native applications
  • Distributed microservices
  • Enterprise SaaS platforms

Common Interview Questions

What is a Profile in Spring Boot?

A Profile in Spring Boot is used to manage environment-specific configurations and beans.

How do you activate a Spring Profile?

Profiles can be activated using:

  • application.properties
  • Command-line arguments
  • Environment variables

What is the purpose of @Profile annotation?

The @Profile annotation loads beans or configurations only for specific environments.


Professional Interview Answer

A Profile in Spring Boot is a feature used to manage environment-specific configurations and bean loading for different environments such as development, testing, staging, and production. Spring Boot loads profile-specific property files and beans based on the active profile. Profiles improve flexibility, maintainability, deployment management, and scalability in enterprise and microservices architectures.


Conclusion

Profiles are one of the most important configuration management features in Spring Boot and Spring Framework.

They enable environment-specific configuration handling, flexible deployments, secure configuration management, and scalable enterprise application architecture.

Modern enterprise systems, banking platforms, cloud-native systems, REST APIs, and microservices architectures heavily rely on Spring Profiles for dynamic and production-ready application deployments.

Understanding Profiles in Spring Boot is essential for Java developers, Spring Boot developers, backend engineers, DevOps engineers, and software architects preparing for interviews and building enterprise-grade applications.

Why this Spring Boot question is important?

This interview question helps candidates understand real-time backend development concepts, practical problem solving, coding fundamentals, system design basics and production-ready application behavior.

Practice this question carefully for Java backend roles, Spring Boot developer interviews, microservices interviews, company interviews and full-stack developer preparation.

About the Author

Naresh Kumar is a Senior Java Backend Engineer with experience building enterprise applications using Java, Spring Boot, Microservices, Docker, Kubernetes and Cloud technologies.