<내부>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
String resource = "resource/db.properties";
        Properties properties = new Properties();
 
        try{
            Reader reader = Resources.getResourceAsReader(resource);
            properties.load(reader);
 
            System.out.println(properties.getProperty("spring.datasource.username"));
            System.out.println(properties.getProperty("spring.datasource.password"));
            System.out.println(properties.getProperty("spring.datasource.url"));
            System.out.println(properties.getProperty("spring.datasource.driverClassName"));
        }catch(IOException e){
            e.printStackTrace();
        }





<외부>

:: .jar와 같은 폴더 내면 db.properties만 적어주면 되는데 그게 아니라면 상대경로 또는 절대경로를 적어준다.


1
2
3
4
5
6
7
8
9
10
11
12
13
FileReader resource = new FileReader("db.properties");
        Properties properties = new Properties();
 
        try{
            properties.load(resource);
 
            System.out.println(properties.getProperty("spring.datasource.username"));
            System.out.println(properties.getProperty("spring.datasource.password"));
            System.out.println(properties.getProperty("spring.datasource.url"));
            System.out.println(properties.getProperty("spring.datasource.driverClassName"));
        }catch(IOException e){
            e.printStackTrace();
        }



'프로그래밍 > Spring' 카테고리의 다른 글

intellij Spring MVC & Gradle 프로젝트 생성  (0) 2020.05.22
Spring MVC & Gradle & Mariadb 연동  (0) 2020.05.21
Spring_AOP  (0) 2020.05.20
SpringMVC_Annotation  (0) 2020.05.20
파일 다운로드  (0) 2018.10.24

+ Recent posts