프로파일과 프로퍼티를 다루는 인터페이스다.
그렇다면 Profile과 Property가 무엇일까?
- Bean들의 그룹이다. 특정 환경에서 어떠한 빈들을 등록할 때 사용할 수 있다.
@Autowired ApplicationContext context; public void run(ApplicationArguments args) throws Exception { Environment env = context.getEnvironment(); System.out.println(Arrays.toString(env.getActiveProfiles())); System.out.println(Arrays.toString(env.getDefaultProfiles())); } 결과값 : [] [default]
현재 아무런 설정을 하지 않았기 때문에 Active값은 ""이며,
Default값은 "default"로 설정된다.
@Profile("test")를 붙이게되면 spring.profile.active="test"로 설정을 했을 경우에만 Bean으로 등록 될 수 있다.
Profile과 비슷하게
env.getProperty("keyName")을 통해 value를 얻어 올 수 있다.
Property 설정시 우선쉬에 대한 내용은
여기누르세요.