스프링 부트 2.4 이상 버전인 경우에 가능한 방법을 기술해둠!!
yml 파일 여러개 사용하기 위해서는
application.yml 파일에 아래와 같은 내용을 추가해주면 된다!
application.yml
spring:
config:
import: classpath:/test.yml
test.yml이라는 파일을 application.yml과 동등한 위치에 만들어주고
내용을 작성한다!
* 추가해주어야할 파일이 여러개라면 classpath:/test.yml, classpath:/test2.yml, classpath:/test3.yml
이런식으로 추가해주면 된다!!!
test.yml
test:
code: hello
MainController를 작성해서 테스트를 진행하겠다
MainController.class
@Controller
public class MainController {
@Value("${test.code}")
private String testCode;
@GetMapping(value="/main")
public @ResponseBody String main() {
System.out.println("test.yml 파일에서 가져옴 : " + testCode);
return "OK";
}
}
실행 결과
'Spring' 카테고리의 다른 글
[Spring] Springboot 프로젝트 생성 (0) | 2023.01.23 |
---|---|
스프링 시큐리티 인증/인가 처리 (0) | 2022.12.09 |
[SpringBoot] SQS 의존성 에러 (0) | 2022.12.04 |
[Redis] redis로 token값 저장하기(2) (0) | 2022.12.01 |
[Redis] redis로 token값 저장하기(1) (0) | 2022.11.30 |