parent
f40ada0389
commit
349337ddf6
@ -0,0 +1,30 @@
|
|||||||
|
package space.kklochko.jdbc_hospital_example.config.env;
|
||||||
|
|
||||||
|
import io.github.cdimascio.dotenv.Dotenv;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
public class DataBaseEnvConfig {
|
||||||
|
public String url;
|
||||||
|
public Properties properties;
|
||||||
|
|
||||||
|
public DataBaseEnvConfig() {
|
||||||
|
Dotenv dotenv = Dotenv
|
||||||
|
.configure()
|
||||||
|
.directory("config")
|
||||||
|
.filename("db")
|
||||||
|
.load();
|
||||||
|
|
||||||
|
setUrl(dotenv.get("JDBC_URL"));
|
||||||
|
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.put("user", dotenv.get("USER"));
|
||||||
|
properties.put("password", dotenv.get("PASSWORD"));
|
||||||
|
|
||||||
|
setProperties(properties);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package space.kklochko.jdbc_hospital_example.config.factories;
|
||||||
|
|
||||||
|
import space.kklochko.jdbc_hospital_example.config.env.DataBaseEnvConfig;
|
||||||
|
import space.kklochko.jdbc_hospital_example.config.models.DataBaseConfig;
|
||||||
|
|
||||||
|
public class LoadDataBaseConfigFromEnvFile {
|
||||||
|
public DataBaseConfig load() {
|
||||||
|
DataBaseEnvConfig dbEnv = new DataBaseEnvConfig();
|
||||||
|
return new DataBaseConfig(dbEnv.getUrl(), dbEnv.getProperties());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package space.kklochko.jdbc_hospital_example.config.models;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DataBaseConfig {
|
||||||
|
public String url;
|
||||||
|
public Properties properties;
|
||||||
|
}
|
Loading…
Reference in new issue