Spring Boot에서 미리 정의된 application.yml 키워드들

백엔드&인프라 추종자·2025년 3월 17일

스프링 공부

목록 보기
29/35

📌 Spring Boot에서 미리 정의된 application.yml 키워드들

Spring Boot는 application.yml 또는 application.properties에서 미리 정해진 키워드(속성)들을 제공합니다.
이 속성들은 Spring이 자동으로 인식하여 특정 기능을 활성화하거나 설정을 조정하는 역할을 합니다.


1. 주요 Spring Boot 설정 키워드

다음은 자주 사용하는 Spring Boot의 공식적인 설정 키워드들입니다.

🔹 1) 애플리케이션 정보

spring:
  application:
    name: MyApp  # 애플리케이션 이름 설정
  • spring.application.name: 애플리케이션 이름을 설정 (서비스 간 로깅, 트레이싱 시 유용)

🔹 2) 프로파일 설정

spring:
  profiles:
    active: dev  # 활성화할 프로파일
  • spring.profiles.active: 활성화할 프로파일 지정 (application-dev.yml, application-prod.yml 등과 함께 사용)
  • spring.profiles.include: 여러 프로파일을 동시에 포함

🔹 3) 서버 설정

server:
  port: 8080  # 서버 포트 지정
  servlet:
    context-path: /api  # 애플리케이션 기본 URL 경로
  • server.port: 서버 포트 번호 설정
  • server.servlet.context-path: 애플리케이션의 기본 URL 경로 설정

🔹 4) 데이터베이스 설정 (spring.datasource)

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: root
    password: secret
    driver-class-name: com.mysql.cj.jdbc.Driver
  • spring.datasource.url: 데이터베이스 연결 URL
  • spring.datasource.username: 데이터베이스 사용자 이름
  • spring.datasource.password: 데이터베이스 비밀번호
  • spring.datasource.driver-class-name: 데이터베이스 드라이버 클래스 이름

🔹 5) JPA 및 Hibernate 설정 (spring.jpa)

spring:
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate.format_sql: true
  • spring.jpa.hibernate.ddl-auto: 테이블 생성 전략 (update, create, none 등)
  • spring.jpa.show-sql: SQL 쿼리 로그 출력 여부
  • hibernate.format_sql: SQL 포맷 정리

🔹 6) Redis 설정 (spring.redis)

spring:
  redis:
    host: localhost
    port: 6379
  • spring.redis.host: Redis 서버 주소
  • spring.redis.port: Redis 포트 번호

🔹 7) 캐싱 설정 (spring.cache)

spring:
  cache:
    type: redis
  • spring.cache.type: 캐시 유형 (예: none, simple, redis 등)

🔹 8) 로깅 설정 (logging)

logging:
  level:
    root: INFO
    com.example: DEBUG
  • logging.level.root: 전체 로그 레벨 설정 (DEBUG, INFO, WARN, ERROR)
  • logging.level.[패키지명]: 특정 패키지의 로그 레벨 설정

🔹 9) 메시지 국제화 (spring.messages)

spring:
  messages:
    basename: messages
    encoding: UTF-8
  • spring.messages.basename: 메시지 번들 파일 (예: messages.properties)
  • spring.messages.encoding: 인코딩 설정

🔹 10) Multipart 파일 업로드 설정 (spring.servlet.multipart)

spring:
  servlet:
    multipart:
      enabled: true
      max-file-size: 10MB
      max-request-size: 50MB
  • spring.servlet.multipart.enabled: 파일 업로드 활성화 여부
  • spring.servlet.multipart.max-file-size: 최대 파일 크기
  • spring.servlet.multipart.max-request-size: 요청당 최대 크기

2. 기타 Spring Boot 설정 키워드

메일 설정 (spring.mail)

spring:
  mail:
    host: smtp.gmail.com
    port: 587
    username: myemail@gmail.com
    password: mypassword
    properties:
      mail.smtp.auth: true
      mail.smtp.starttls.enable: true

Spring Security 설정 (spring.security)

spring:
  security:
    user:
      name: admin
      password: secret
  • spring.security.user.name: 기본 사용자 이름
  • spring.security.user.password: 기본 사용자 비밀번호

Spring Cloud Config 설정 (spring.cloud.config)

spring:
  cloud:
    config:
      uri: http://config-server:8888
      fail-fast: true

📌 정리: Spring Boot에서 미리 정의된 주요 키워드

카테고리설정 키워드설명
애플리케이션spring.application.name애플리케이션 이름 설정
프로파일spring.profiles.active활성화할 프로파일 지정
서버server.port서버 포트 설정
데이터베이스spring.datasource.urlDB 연결 URL
JPAspring.jpa.hibernate.ddl-auto테이블 자동 생성 옵션
Redisspring.redis.hostRedis 서버 주소
캐시spring.cache.type캐시 유형 선택
로깅logging.level.root기본 로그 레벨
국제화spring.messages.basename다국어 메시지 파일 지정
파일 업로드spring.servlet.multipart.max-file-size최대 파일 크기 제한
이메일spring.mail.hostSMTP 서버 설정
보안spring.security.user.name기본 관리자 계정 설정
Spring Cloudspring.cloud.config.uriConfig 서버 URI

📢 결론

  • spring: 키워드는 Spring Boot에서 미리 정해진 설정 값들을 관리하는 고정된 네임스페이스입니다.
  • 사용자는 myapp: 같은 별도의 네임스페이스를 만들어 커스텀 설정을 추가할 수 있습니다.
  • Spring Boot 공식 문서를 참고하면 더 많은 키워드를 찾을 수 있습니다. (Spring Boot Docs)

💡 추가 설정이 필요하면 말씀해 주세요! 😊

profile
AI 답변 글을 주로 올립니다.

0개의 댓글