0Pricing
Spring Boot 4 Microservices & REST APIs · 강의

환경별 프로필

프로필을 사용해 환경마다 구성을 전환해 보세요.

환경별 프로필은(는) CoddyKit의 무료 Spring Boot 4 Microservices & REST APIs 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Spring Boot 4 Microservices & REST APIs 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Spring Boot 4 Microservices & REST APIs 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Profiles Exist

Real applications run in several environments — local, dev, staging, production — each needing different datasources, log levels, and feature toggles. Profiles let one codebase carry many configurations and activate the right set at runtime.

A profile is just a named label. Beans and property files can be tagged so they apply only when that profile is active.

Profile-Specific Property Files

Boot automatically loads application-{profile}.yml on top of the base application.yml. The profile file overrides matching keys while inheriting everything else.

# application.yml (base, always loaded)
spring:
  jpa:
    show-sql: false

# application-dev.yml (loaded when dev active)
spring:
  jpa:
    show-sql: true
  datasource:
    url: jdbc:h2:mem:devdb

Activating a Profile

Set spring.profiles.active to choose which profiles run. You can do this in a file, as an environment variable, or on the command line.

# Command line
java -jar app.jar --spring.profiles.active=prod

# Environment variable
export SPRING_PROFILES_ACTIVE=prod

# Multiple profiles
java -jar app.jar --spring.profiles.active=prod,metrics

Conditional Beans with @Profile

@Profile on a bean or configuration class makes it register only when that profile is active. This is ideal for swapping implementations between environments.

@Configuration
public class PaymentConfig {
    @Bean
    @Profile("prod")
    public PaymentGateway liveGateway() {
        return new StripeGateway();
    }

    @Bean
    @Profile("!prod")
    public PaymentGateway fakeGateway() {
        return new InMemoryGateway();
    }
}

Profile Expressions

The @Profile value supports simple logic: ! for NOT, & for AND, and | for OR. Group expressions with parentheses.

@Profile("!prod")                // anything except prod
@Profile("prod & metrics")       // both active
@Profile("dev | test")           // either active
@Profile("prod & (eu | us)")     // grouped

The Default Profile

When no profile is active, Spring enables the implicit default profile. You can target it explicitly with @Profile("default") for fallback beans used during plain local runs.

@Bean
@Profile("default")
public DataSeeder localSeeder() {
    return new SampleDataSeeder();
}

Profile Groups

A profile group bundles several profiles under one name, so activating the group activates them all. Great for composing cross-cutting concerns.

spring:
  profiles:
    group:
      production:
        - prod
        - metrics
        - swagger-off
# Now: --spring.profiles.active=production turns on all three

Including Profiles

spring.profiles.active sets the primary profiles, while spring.profiles.include adds extra ones unconditionally, regardless of which primary profile is selected.

spring:
  profiles:
    include:
      - common-logging
      - audit

Inspecting Active Profiles at Runtime

You can read active profiles from the Environment bean. This is useful for guard logic or for logging which configuration is live.

@Component
public class StartupLogger {
    private final Environment env;
    public StartupLogger(Environment env) { this.env = env; }

    @PostConstruct
    void log() {
        System.out.println("Active: "
            + String.join(",", env.getActiveProfiles()));
    }
}

Profiles in Tests

In integration tests, annotate the class with @ActiveProfiles to force a specific configuration, such as an in-memory database profile.

@SpringBootTest
@ActiveProfiles("test")
class OrderServiceTest {
    // loads application-test.yml + @Profile("test") beans
}

Common Pitfalls

Watch for these mistakes:

  • Forgetting to set spring.profiles.active in production, so dev defaults leak in
  • Putting secrets in application-dev.yml and committing it
  • Overusing @Profile where a simple property toggle would do

Quick Check

Test your grasp of profile expressions.

Recap

Profiles tailor one codebase to many environments.

  • application-{profile}.yml overrides base config
  • Activate via spring.profiles.active (file, env var, or CLI)
  • @Profile conditionally registers beans, with !, &, | expressions
  • Profile groups bundle related profiles
  • Use @ActiveProfiles in tests

자주 묻는 질문

“환경별 프로필” 강의는 무료인가요?

네 — “환경별 프로필” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Spring Boot 4 Microservices & REST APIs 강의 전체를 잠금 해제할 수 있습니다. Spring Boot 4 Microservices & REST APIs 강의에는 총 4개의 강의가 포함되어 있습니다.

“환경별 프로필”에서 뭘 배우나요?

프로필을 사용해 환경마다 구성을 전환해 보세요. 브라우저에서 직접 실행하는 실습 코드로 Spring Boot 4 Microservices & REST APIs을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Spring Boot 4 Microservices & REST APIs을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Spring Boot 4 Microservices & REST APIs은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“환경별 프로필” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Spring Boot 4 Microservices & REST APIs 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Spring Boot 4 Microservices & REST APIs 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. application.properties와 YAML
  2. 환경별 프로필
  3. @ConfigurationProperties로 타입 안전한 구성
  4. 외부 구성과 구성 재정의
← Spring Boot 4 Microservices & REST APIs(으)로 돌아가기