-
API 키 숨기기 ( Spring Legacy 에서 properties 이용하기 )Spring 2023. 5. 14. 22:23
API key나 아이디 , 비밀번호 같이 프로젝트를 하다보면 숨겨야할 정보들이 있다.
이번에는 spring legacy project에서 해당 정보들을 .properties 파일에 저장해서 사용하고,
깃허브에는 .properties 파일을 gitignore 파일에 추가해서 개인정보가 유출되지 않도록 할 것이다.
먼저, src/main/resources 경로에 .properties 파일을 생성하자
src/main/resources 경로는 classpath 라고도 한다.
root-context , servlet-context 설정
root-context와 servlet-context에 PropertyPlaceholderConfigurer 를 사용할 수 있도록 Bean을 설정한다
사용하기
원하는 properties를 @Value 어노테이션으로 불러와서 Controller / Service 등의 java 파일에서 사용할 수 있다.
jsp 파일에서는 ${kakaoMapApiKey} 형태로 사용할 수 있다.
Spring legacy의 경우, Spring boot나 react 보다 훨씬 불편하게 되어있다;
'Spring' 카테고리의 다른 글
gitignore 생성 ( spring legacy ) (0) 2023.05.14 게시판 파일첨부 ( 2. DB에 저장 및 detail에 Attach ) (0) 2023.04.14 게시판 파일 첨부 (1. 파일을 임시 보관소에 저장하기 ) (0) 2023.04.14 ajax (0) 2023.04.10 회원가입, 로그인, 게시판 백엔드 실습( 댓글 리스트 , pagenation ) (0) 2023.04.06