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

외부 구성과 구성 재정의

환경과 명령줄을 통해 구성을 재정의해 보세요.

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

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

The 12-Factor Idea

A core principle of portable apps is storing configuration in the environment, not in code. The same artifact should run anywhere, with behavior changed only by external config.

Spring Boot embraces this: a single jar reads from many sources and merges them with a well-defined precedence.

Many Sources, One Environment

Boot collects configuration from numerous property sources — files, environment variables, command-line args, and more — into one unified Environment.

  • Each source contributes key/value pairs
  • Higher-priority sources win on conflicts
  • Your code never knows or cares where a value came from

Precedence Order (High to Low)

When the same key appears in several sources, the highest-priority source wins. A simplified, commonly used ordering:

  • Command-line arguments
  • OS environment variables
  • Profile-specific application-{profile} files
  • Base application files
  • Defaults in code / @Value fallbacks

This is why a CLI flag can override anything baked into the jar.

Overriding with Command-Line Args

Pass --key=value after the jar. These have very high precedence and are ideal for one-off overrides or container entrypoints.

java -jar app.jar \
  --server.port=9090 \
  --spring.profiles.active=prod \
  --app.mail.host=smtp.prod.example.com

Overriding with Environment Variables

Environment variables use an UPPER_SNAKE_CASE form of the property name: dots and dashes become underscores. This is the standard way to inject config in containers.

# property: app.mail.host
export APP_MAIL_HOST=smtp.prod.example.com

# property: server.port
export SERVER_PORT=9090

# property: spring.datasource.password
export SPRING_DATASOURCE_PASSWORD=s3cret

Relaxed Binding for Env Vars

Because env var names are constrained, Spring maps them back to canonical property names. APP_MAIL_MAX_RETRIES resolves to app.mail.maxRetries. This lets you set any property from the environment.

Injecting Secrets at Deploy Time

Keep secrets out of the jar; reference them with placeholders and let the platform supply real values via env vars. The committed file holds only a safe default or none.

spring:
  datasource:
    url: ${DB_URL}
    username: ${DB_USER:app}
    password: ${DB_PASSWORD}

External Config Files

Point Boot at config outside the jar with spring.config.location or add extra files with spring.config.additional-location. Operators can drop a file next to the deployment without rebuilding.

java -jar app.jar \
  --spring.config.additional-location=file:/etc/myapp/

Importing Config

Modern Boot supports spring.config.import to pull in extra documents, optional files, or even config server entries, merged with the normal precedence rules.

spring:
  config:
    import:
      - optional:file:/etc/myapp/override.yml
      - configserver:

Random Values

The random property source generates values on demand — handy for test data or ephemeral identifiers, though not for stable secrets.

app:
  instance-id: ${random.uuid}
  jitter-ms: ${random.int(0,500)}

Debugging Where a Value Came From

When a value is not what you expect, inspect the merged Environment. The actuator /env endpoint lists every property source and the winning value, making precedence problems easy to diagnose.

# requires spring-boot-starter-actuator + exposure
GET /actuator/env/server.port

Quick Check

Test your understanding of precedence.

Recap

Externalized config makes one artifact run everywhere.

  • Many sources merge into one Environment by precedence
  • CLI args > env vars > profile files > base files > code defaults
  • Env vars use UPPER_SNAKE_CASE relaxed binding
  • Inject secrets via placeholders at deploy time
  • Use /actuator/env to debug where a value originated

자주 묻는 질문

“외부 구성과 구성 재정의” 강의는 무료인가요?

네 — “외부 구성과 구성 재정의” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 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개 중 4번째 강의입니다.

“외부 구성과 구성 재정의” 강의는 얼마나 걸리나요?

대부분의 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(으)로 돌아가기