Explorar el Código

Solve the resources file reading problem

jiequan.bi hace 5 años
padre
commit
07063e05fe

+ 4 - 5
jeecg-boot-base-common/src/main/java/org/jeecg/common/util/JsonResourceUtil.java

@@ -7,9 +7,9 @@ import org.apache.commons.io.FileUtils;
 import org.jeecg.common.constant.AccountReportConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.core.io.ClassPathResource;
 
 import java.io.File;
-import java.net.URL;
 import java.util.*;
 
 /**
@@ -29,11 +29,10 @@ public class JsonResourceUtil {
             filename += ".json";
         }
         try {
-            URL url = JsonResourceUtil.class.getResource(filename);
-            String path = url.getPath();
-            File file = new File(path);
+            ClassPathResource classPathResource = new ClassPathResource(filename);
+            File file = classPathResource.getFile();
             if (file.exists()) {
-                String content = FileUtils.readFileToString(file, "UTF-8");
+                String content = FileUtils.readFileToString(classPathResource.getFile(), "UTF-8");
                 json = JSON.parseObject(content);
             } else {
                 logger.info("file not exist!");