Исправить загрузку внешнего application.properties
This commit is contained in:
parent
84e0f039cb
commit
f3e4233285
@ -3,6 +3,9 @@ package utils.config;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
public final class AppConfig {
|
||||
@ -26,18 +29,30 @@ public final class AppConfig {
|
||||
}
|
||||
|
||||
private void load() {
|
||||
try (InputStream in = getClass().getClassLoader()
|
||||
.getResourceAsStream("application.properties")) {
|
||||
|
||||
try (InputStream in = getClass().getClassLoader().getResourceAsStream("application.properties")) {
|
||||
if (in == null) {
|
||||
throw new RuntimeException("Config file application.properties not found");
|
||||
}
|
||||
|
||||
properties.load(in);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to load application.properties", e);
|
||||
}
|
||||
|
||||
Path externalConfig = Paths.get("application.properties");
|
||||
if (!Files.isRegularFile(externalConfig)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Properties override = new Properties();
|
||||
try (InputStream in = Files.newInputStream(externalConfig)) {
|
||||
override.load(in);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to load external application.properties from " + externalConfig.toAbsolutePath(), e);
|
||||
}
|
||||
|
||||
for (String name : override.stringPropertyNames()) {
|
||||
properties.setProperty(name, override.getProperty(name));
|
||||
}
|
||||
}
|
||||
|
||||
/** Вернёт значение строки или null, если параметр не найден */
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
client.version=1.2.271
|
||||
server.version=1.2.251
|
||||
client.version=1.2.272
|
||||
server.version=1.2.252
|
||||
|
||||
Loading…
Reference in New Issue
Block a user