Fix reading components versions for jar
@@ -22,11 +22,12 @@ import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
-import org.springframework.util.ResourceUtils;
-import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.Collections;
import java.util.Map;
@@ -34,15 +35,23 @@ import java.util.Map;
@Slf4j
public class ApplicationInfoManager {
- @Value("${app.component.version.file:classpath:static/components_versions.json}")
- private String componentVersionFile;
+ private final String componentVersionFile;
+ private final ResourceLoader resourceLoader;
+
+ public ApplicationInfoManager(
+ final @Value("${app.component.version.file:classpath:static/components_versions.json}")
+ String componentVersionFile,
+ final ResourceLoader resourceLoader) {
+ this.componentVersionFile = componentVersionFile;
+ this.resourceLoader = resourceLoader;
+ }
public ApplicationInfo getInfo() {
return new ApplicationInfo(getComponentVersions());
}
private Map<String, String> getComponentVersions() {
- try (FileReader reader = new FileReader(ResourceUtils.getFile(componentVersionFile))) {
+ try (Reader reader = new InputStreamReader(resourceLoader.getResource(componentVersionFile).getInputStream())) {
final String content = String.join("\n", IOUtils.readLines(reader));
return JsonMapper.parseData(content, new TypeReference<Map<String, String>>() {});
} catch (IOException e) {
