diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-18 13:47:56 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-18 13:47:56 -0700 |
commit | 4d59dd0973479bca3d51cf3bba6b0769a0d671c3 (patch) | |
tree | de4276f0b05490988199e4af0049ea4c774c959e /src/main/java/org/traccar/config | |
parent | e65bfeab8dafb02c21b360b4970d5d94013f53f6 (diff) | |
download | trackermap-server-4d59dd0973479bca3d51cf3bba6b0769a0d671c3.tar.gz trackermap-server-4d59dd0973479bca3d51cf3bba6b0769a0d671c3.tar.bz2 trackermap-server-4d59dd0973479bca3d51cf3bba6b0769a0d671c3.zip |
Fix config injection
Diffstat (limited to 'src/main/java/org/traccar/config')
-rw-r--r-- | src/main/java/org/traccar/config/Config.java | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/config/Config.java b/src/main/java/org/traccar/config/Config.java index 815a6e86a..5f95c16d9 100644 --- a/src/main/java/org/traccar/config/Config.java +++ b/src/main/java/org/traccar/config/Config.java @@ -16,13 +16,18 @@ package org.traccar.config; import com.google.common.annotations.VisibleForTesting; +import com.google.inject.name.Named; +import org.traccar.helper.Log; +import javax.inject.Inject; +import javax.inject.Singleton; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.InvalidPropertiesFormatException; import java.util.Properties; +@Singleton public class Config { private final Properties properties = new Properties(); @@ -32,7 +37,8 @@ public class Config { public Config() { } - public Config(String file) throws IOException { + @Inject + public Config(@Named("configFile") String file) throws IOException { try { Properties mainProperties = new Properties(); try (InputStream inputStream = new FileInputStream(file)) { @@ -50,8 +56,14 @@ public class Config { useEnvironmentVariables = Boolean.parseBoolean(System.getenv("CONFIG_USE_ENVIRONMENT_VARIABLES")) || Boolean.parseBoolean(properties.getProperty("config.useEnvironmentVariables")); + + Log.setupLogger(this); } catch (InvalidPropertiesFormatException e) { + Log.setupDefaultLogger(); throw new RuntimeException("Configuration file is not a valid XML document", e); + } catch (Exception e) { + Log.setupDefaultLogger(); + throw e; } } |