Spring
Spring Core 라이브러리 이용해서 Properties 파일 데이터 읽기
jayden-lee
2019. 5. 28. 16:03
728x90
public class Main {
public static void main(String[] args) throws Exception {
Resource resource = new ClassPathResource("custom.properties"); // 1
Properties properties = PropertiesLoaderUtils.loadProperties(resource); // 2
System.out.println(properties); // 3
}
}
1. custom.properties 파일 데이터를 가져와서 Resource 객체로 캐스팅
2. PropertiesLoaderUtils 유틸 클래스를 이용해서 Properties 객체로 변환
3. properties 객체 내용 출력