yml 설정 파일 프로필(환경)별로 분리하기 - Spring

김태훈·2023년 8월 2일
0
spring:
  profiles:
    active: local
    
logging:
  config: classpath:logback-${spring.profiles.active}.xml

jwt:
  secret: [시크릿 키]
  token-validity-in-seconds: [몇초]
  domain: localhost

naver:
  id: [이메일인증 아이디]
  pwd: [이메일인증 비밀번호]
  email: [이메일]
  port: 465

server:
  servlet:
    context-path: /api

---
spring:
  profiles: local
  datasource:
    driver-class-name: [H2 드라이버]
logging:
  level:
    root: debug # 로컬은 debug
---

spring:
  profiles: prod
  datasource:
    driver-class-name: org.postgresql.Driver
    url: [RDS 엔드포인트]
    username: [RDS username]
    password: [RDS 비밀번호]
  data:
    redis:
      host: 127.0.0.1
      port: 6379
sentry:
  dsn: [dsn정보]
  traces-sample-rate: 1.0
---

다음과 같이 설정파일을 정의했었다.

하지만, 몇가지 deprecated된 것이 있었다.
스프링은 오류메세지도 "뭐로 replcae 해주세요! 라고 친절하므로, 무작정 구글링하다기보다는, 횡스크롤로 밀면서 확인해보자.

고쳐진 yml파일은 다음과 같다.

spring:
  profiles:
    active: local #수정됨
    
logging:
  config: classpath:logback-${spring.profiles.active}.xml #수정됨

jwt:
  secret: [시크릿 키]
  token-validity-in-seconds: [몇초]
  domain: localhost

naver:
  id: [이메일인증 아이디]
  pwd: [이메일인증 비밀번호]
  email: [이메일]
  port: 465

server:
  servlet:
    context-path: /api

---
spring:
  config:
    activate:
      on-profile: local
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:tcp://localhost/~/test;MODE=PostgreSQL;INIT=RUNSCRIPT FROM 'classpath:sql/createTable.sql';DATABASE_TO_UPPER=false;CASE_INSENSITIVE_IDENTIFIERS=true
    username: sa
  sql:
    init:
      mode: always
logging:
  level:
    root: info
---

spring:
  profiles: prod
  datasource:
    driver-class-name: org.postgresql.Driver
    url: [RDS 엔드포인트]
    username: [RDS username]
    password: [RDS 비밀번호]
  data:
    redis:
      host: 127.0.0.1
      port: 6379
sentry:
  dsn: [dsn정보]
  traces-sample-rate: 1.0

수정!

h2 postgresql 모드로 테스트하면 자꾸 syntax error가 나는경우가 있음.
그래서 h2대신에 localhost postgresql DB를 직접 연동하여 사용할 예정

spring:
  profiles:
    active: local #수정됨
    
logging:
  config: classpath:logback-${spring.profiles.active}.xml #수정됨

jwt:
  secret: [시크릿 키]
  token-validity-in-seconds: [몇초]
  domain: localhost

naver:
  id: [이메일인증 아이디]
  pwd: [이메일인증 비밀번호]
  email: [이메일]
  port: 465

server:
  servlet:
    context-path: /api

---
spring:
  config:
    activate:
      on-profile: local
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/postgres
    username: postgres
    password:
  sql:
    init:
      mode: always
logging:
  level:
    root: info
---

spring:
  profiles: prod
  datasource:
    driver-class-name: org.postgresql.Driver
    url: [RDS 엔드포인트]
    username: [RDS username]
    password: [RDS 비밀번호]
  data:
    redis:
      host: 127.0.0.1
      port: 6379
sentry:
  dsn: [dsn정보]
  traces-sample-rate: 1.0
profile
기록하고, 공유합시다

0개의 댓글