feat: add config file
This commit is contained in:
parent
c59f4fbed1
commit
168e9a99c7
4
resources/application.properties
Normal file
4
resources/application.properties
Normal file
@ -0,0 +1,4 @@
|
||||
app.datasource.url=jdbc:postgresql://localhost:5434/charm_repository
|
||||
app.datasource.username=postgres
|
||||
app.datasource.password=123456
|
||||
app.datasource.driver=org.postgresql.Driver
|
||||
@ -8,6 +8,7 @@ import ru.charm.back.model.Gender;
|
||||
import ru.charm.back.model.Profile;
|
||||
import ru.charm.back.model.Role;
|
||||
import ru.charm.back.model.Status;
|
||||
import ru.charm.back.utils.ConfigFile;
|
||||
|
||||
import java.sql.*;
|
||||
import java.sql.Date;
|
||||
@ -18,14 +19,15 @@ import java.util.*;
|
||||
public class ProfileDao {
|
||||
|
||||
private static final ProfileDao INSTANCE = new ProfileDao();
|
||||
public static final String URL = "jdbc:postgresql://localhost:5434/charm_repository";
|
||||
public static final String USER = "postgres";
|
||||
public static final String PASSWORD = "123456";
|
||||
public static final String URL = ConfigFile.get("app.datasource.url");
|
||||
public static final String USER = ConfigFile.get("app.datasource.username");
|
||||
public static final String PASSWORD = ConfigFile.get("app.datasource.password");
|
||||
public static final String DRIVER = ConfigFile.get("app.datasource.driver");
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public static ProfileDao getInstance() {
|
||||
Class.forName("org.postgresql.Driver");
|
||||
Class.forName(DRIVER);
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
29
src/ru/charm/back/utils/ConfigFile.java
Normal file
29
src/ru/charm/back/utils/ConfigFile.java
Normal file
@ -0,0 +1,29 @@
|
||||
package ru.charm.back.utils;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
@UtilityClass
|
||||
public class ConfigFile {
|
||||
private static final Properties CONFIG = new Properties();
|
||||
|
||||
static {
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
public static String get(String key) {
|
||||
return CONFIG.getProperty(key);
|
||||
}
|
||||
|
||||
|
||||
private static void loadConfig() {
|
||||
try (InputStream resourceAsStream = ConfigFile.class.getClassLoader().getResourceAsStream("application.properties")) {
|
||||
CONFIG.load(resourceAsStream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user