env 파일 추가

- resources 폴더 아래에 properties 폴더를 만들고 환경변수 파일인 env.properties를 만든다
# mysql 관련 설정
mysql.url=url 입력
mysql.username=사용자 계정 입력
mysql.password=비밀번호 입력
#jwt secret
env.jwt.secret=사용할 jwt secret 입력
- 현재는 mysql, jwt secret 변수만 넣었고 필요한 환경 변수들은 여기에 추가하면 됨
env 설정 추가

- 다음과 같은 경로에 env 패키지와 EnvConfig 클래스 생성
package com.ssafy.backend.env;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
@Configuration
@PropertySources(@PropertySource("classpath:properties/env.properties")) //env.propoerties 파일 소스 등록
public class EnvConfig {
}
- 빈으로 등록하여 읽을 수 있게 Confguration 어노테이션을 달아줌
- 등록할 파일의 경로를 PropertySources 어노테이션을 이용하여 달아줌
gitignore 설정
### env ###
!**/properties/
env.properties
- gitignore에 파일의 경로나 파일이름을 등록해서 깃이 읽지 못하게 함
git에 올리기
- 혹시 git status 명령어를 입력했을 때 gitignore에 적용되지 않는 경우
- git rm -r —cached . 명령어 입력 → git에 있는 캐시파일을 지워줌
- 이미 add 해버리고 확인해보니 gitignore에 적용되지 않은 경우
- git reset HEAD [파일명]
→ add 명령어를 사용하여 올린 파일을 취소함
→ 파일명 안적으면 최근에 add 한거 다 날림
- 후에 위의 git rm -r —cached . 명령어 입력 후 add,commit 진행