Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- programmers
- BFS
- boj
- aws
- Data Structure
- django
- 시뮬레이션
- SQL
- GitHub
- Vue.js
- hash table
- Priority Queue
- JavaScript
- 알고리즘
- Back tracking
- Python
- DFS
- 코테
- 알고리듬
- CSV
- Linked list
- spring boot
- Algorithm
- gpdb
- 모의SW역량테스트
- SWEA
- 구현
- Trie
- 코딩테스트
- Bruth Force
Archives
- Today
- Total
hotamul의 개발 이야기
[Spring-Boot] 환경 변수 저장 및 사용 방법 본문
Spring Boot에서는 config
디렉토리에 환경 변수 파일을 저장할 수 있다. 기본적으로 Spring Boot는 아래 나열된 순서대로 환경 변수 파일을 찾는다.
- A
config
subdirectory of the current directory. - The current directory.
- A classpath
/config
package.
config
디렉토리에 .env
파일을 만들어 환경 변수들을 저장하고
DB_HOST=localhost
DB_PORT=5432
DB_USER=admin
DB_PASSWORD=secret
아래 처럼 @Value
annotation로 해당 변수들을 사용하면 된다.
@RestController
public class MyController {
@Value("${DB_HOST}")
private String dbHost;
@Value("${DB_PORT}")
private int dbPort;
@Value("${DB_USER}")
private String dbUser;
@Value("${DB_PASSWORD}")
private String dbPassword;
@GetMapping("/db")
public String getDbInfo() {
return "DB Host: " + dbHost + ", DB Port: " + dbPort + ", DB User: " + dbUser + ", DB Password: " + dbPassword;
}
}
'Dev. > Spring-Boot' 카테고리의 다른 글
Configuration, proxyBeanMethods (0) | 2023.09.07 |
---|---|
Meta Annotation, Composed Annotation (0) | 2023.09.05 |
Spring Boot는 왜 jar 파일로 실행 가능할까 (0) | 2023.09.02 |
Spring Boot가 뭔데? (0) | 2023.08.15 |
Comments