Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot JHipster应用程序内的类路径资源_Spring Boot_Jhipster - Fatal编程技术网

Spring boot JHipster应用程序内的类路径资源

Spring boot JHipster应用程序内的类路径资源,spring-boot,jhipster,Spring Boot,Jhipster,在参考资料中的JHipster(版本6.4.1)应用程序中,我有一个名为static的目录,其中我放置了一个服务所需的JSON文件。文件名为standards.json。 在我的服务中,我希望以非常简单的方式读取此文件: try { ClassPathResource cpr = new ClassPathResource("static/standards.json"); byte[] bdata = FileCopyUtils.copyToByteArray(

在参考资料中的JHipster(版本6.4.1)应用程序中,我有一个名为static的目录,其中我放置了一个服务所需的JSON文件。文件名为standards.json。 在我的服务中,我希望以非常简单的方式读取此文件:

try {
        ClassPathResource cpr = new ClassPathResource("static/standards.json");
        byte[] bdata = FileCopyUtils.copyToByteArray(cpr.getInputStream());
        String content = new String(bdata, StandardCharsets.UTF_8);
        Gson g = new Gson();
        data = g.fromJson(content, StandardLevel[].class);

        // here I am doing something with data
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
但不幸的是,我遇到了运行时错误:

class path resource [static/standards.json] cannot be opened because it does not exist
这很奇怪,因为当我在“干净”的Spring引导应用程序中以同样的方式进行操作时,没有JHipster,一切都正常工作。
你知道为什么它不在这里工作吗?或者我应该如何使用静态JSOn文件,这是我的后端所必需的?

是“static/standards.JSOn”还是“static/data/standards.JSOn”?只是为了确认这不是一个简单的打字错误:)对不起,我错了。它是“static/standards.json”。项目相对位置是
src/main/resources/static/standards.json
,对吗?您是否使用mvnw运行应用程序?