Skip to content

Commit 9b8552f

Browse files
author
Tanechka
committed
Lesson17 DB_credentials_as_resources
1 parent 10c521a commit 9b8552f

2 files changed

Lines changed: 5 additions & 13 deletions

File tree

config/resumes.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
storage.dir=C:/projects/basejava/storage
2+
3+
# Replace by Heroku credentials
24
db.url=jdbc:postgresql://localhost:5432/resumes
35
db.user=postgres
46
db.password=postgres

src/ru/javawebinar/basejava/Config.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
import ru.javawebinar.basejava.storage.Storage;
55

66
import java.io.File;
7-
import java.io.FileInputStream;
87
import java.io.IOException;
98
import java.io.InputStream;
109
import java.util.Properties;
1110

1211
public class Config {
13-
private static final File PROPS = new File(getHomeDir(), "config\\resumes.properties");
12+
private static final String PROPS = "/resumes.properties";
1413
private static final Config INSTANCE = new Config();
1514

1615
private final File storageDir;
@@ -21,13 +20,13 @@ public static Config get() {
2120
}
2221

2322
private Config() {
24-
try (InputStream is = new FileInputStream(PROPS)) {
23+
try (InputStream is = Config.class.getResourceAsStream(PROPS)) {
2524
Properties props = new Properties();
2625
props.load(is);
2726
storageDir = new File(props.getProperty("storage.dir"));
2827
storage = new SqlStorage(props.getProperty("db.url"), props.getProperty("db.user"), props.getProperty("db.password"));
2928
} catch (IOException e) {
30-
throw new IllegalStateException("Invalid config file " + PROPS.getAbsolutePath());
29+
throw new IllegalStateException("Invalid config file " + PROPS);
3130
}
3231
}
3332

@@ -38,13 +37,4 @@ public File getStorageDir() {
3837
public Storage getStorage() {
3938
return storage;
4039
}
41-
42-
private static File getHomeDir() {
43-
String prop = System.getProperty("homeDir");
44-
File homeDir = new File(prop == null ? "." : prop);
45-
if (!homeDir.isDirectory()) {
46-
throw new IllegalStateException(homeDir + " is not directory");
47-
}
48-
return homeDir;
49-
}
5040
}

0 commit comments

Comments
 (0)