提交 9a574641 编写于 作者: xieshanghe's avatar xieshanghe

fixed bug:ResourceUtils can't read resoucre from jar.

上级 8bf5e00c
......@@ -19,7 +19,7 @@
package org.skywalking.apm.collector.core.module;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.Reader;
import java.util.Map;
import org.skywalking.apm.collector.core.config.ConfigLoader;
import org.skywalking.apm.collector.core.framework.DefineException;
......@@ -39,8 +39,8 @@ public class ModuleConfigLoader implements ConfigLoader<Map<String, Map>> {
Yaml yaml = new Yaml();
try {
try {
FileReader applicationFileReader = ResourceUtils.read("application.yml");
return (Map<String, Map>)yaml.load(applicationFileReader);
Reader applicationReader = ResourceUtils.read("application.yml");
return (Map<String, Map>)yaml.load(applicationReader);
} catch (FileNotFoundException e) {
logger.info("Could not found application.yml file, use default");
return (Map<String, Map>)yaml.load(ResourceUtils.read("application-default.yml"));
......
......@@ -18,9 +18,10 @@
package org.skywalking.apm.collector.core.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
/**
......@@ -28,12 +29,12 @@ import java.net.URL;
*/
public class ResourceUtils {
public static FileReader read(String fileName) throws FileNotFoundException {
public static Reader read(String fileName) throws FileNotFoundException {
URL url = ResourceUtils.class.getClassLoader().getResource(fileName);
if (url == null) {
throw new FileNotFoundException("file not found: " + fileName);
}
File file = new File(ResourceUtils.class.getClassLoader().getResource(fileName).getFile());
return new FileReader(file);
InputStream inputStream = ResourceUtils.class.getClassLoader().getResourceAsStream(fileName);
return new InputStreamReader(inputStream);
}
}
package org.skywalking.apm.collector.core.module;
import java.util.Map;
import org.junit.Assert;
import org.junit.Test;
import org.skywalking.apm.collector.core.framework.DefineException;
public class ModuleConfigLoaderTestCase {
@SuppressWarnings({ "rawtypes" })
@Test
public void testLoad() throws DefineException {
ModuleConfigLoader configLoader = new ModuleConfigLoader();
Map<String, Map> configuration = configLoader.load();
Assert.assertNotNull(configuration.get("cluster"));
Assert.assertNotNull(configuration.get("cluster").get("zookeeper"));
}
}
package org.skywalking.apm.collector.core.utils;
import java.io.IOException;
import java.io.Reader;
import org.junit.Assert;
import org.junit.Test;
import org.skywalking.apm.collector.core.util.ResourceUtils;
public class ResourceUtilsTestCase {
@Test
public void testRead() throws IOException {
Reader reader = ResourceUtils.read("application.yml");
Assert.assertNotNull(reader);
reader.close();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册