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 |
Tags
- aws
- gpdb
- BFS
- 알고리듬
- 구현
- JavaScript
- Priority Queue
- boj
- Vue.js
- GitHub
- Python
- 시뮬레이션
- Data Structure
- 알고리즘
- Bruth Force
- SWEA
- CSV
- SQL
- hash table
- Algorithm
- Back tracking
- 모의SW역량테스트
- spring boot
- django
- Trie
- 코테
- programmers
- Linked list
- DFS
- 코딩테스트
Archives
- Today
- Total
hotamul의 개발 이야기
[Spring-Boot] 환경 변수 저장 및 사용 방법 본문
Spring Boot에서는 config 디렉토리에 환경 변수 파일을 저장할 수 있다. 기본적으로 Spring Boot는 아래 나열된 순서대로 환경 변수 파일을 찾는다.
- A
configsubdirectory of the current directory. - The current directory.
- A classpath
/configpackage.
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