Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 50

    Spring Boot Profiles

    Profiles let one binary behave differently per environment.

    Course progress0%
    Focus
    2 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Profiles let one binary behave differently per environment. Activate with SPRING_PROFILES_ACTIVE=prod or --spring.profiles.active=prod.

    Informative example

    bash
    # application.yml ← shared defaults
    server:
    port: 8080
    # application-dev.yml ← only when dev profile active
    spring:
    jpa:
    hibernate:
    ddl-auto: update
    logging:
    level:
    com.acme: DEBUG
    # application-prod.yml
    spring:
    jpa:
    hibernate:
    ddl-auto: validate
    logging:
    level:
    com.acme: INFO
    // Profile-scoped beans
    @Service
    @Profile("!prod")
    public class MockEmailSender implements EmailSender { ... }
    @Service
    @Profile("prod")
    public class SesEmailSender implements EmailSender { ... }
    Ready to mark this lesson complete?Track your journey across the entire course.