Springboot Properties 분리하기

정재현·2022년 12월 2일
0

개발을 진행하다 보면 git에 민감정보가 올라가는 경우가 있다.

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/social
    username: ?
    password: ?
    driver-class-name: com.mysql.cj.jdbc.Driver

데이터베이스의 패스워드나 API의 키 등 사용자 정보를 분리해서 작성해보자.

  1. 데이터 정보를 명시할 yml파일 생성
    이때 파일명을 applicaiont-[이름].yml로 작성

application-db.yml 파일

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/social
    username: user-name
    password: user-password
    driver-class-name: com.mysql.cj.jdbc.Driver
  1. application.yml 파일 수정

아래와 같이 application-[] => 괄호안의 이름 포함시키기

spring:
  profiles:
    include:
      - oauth
      - db
  1. gitignore파일에 민감정보 파일 포함시키기
    이미 민감정보파일을 git에 push했다면
    git rm --cached 파일명 => 원격 저장소 파일 삭제
    git commit -m "내용"
    git push ~ ~

    git rm [--cached] 파일명 : --cached 옵션이 있으면 원격 저장소 파일만 아니면 로컬까지 삭제

profile
back end개발자로 성장하기

0개의 댓글