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

在我的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

这很奇怪,因为当我在没有JHipster的“干净” Spring Boot应用程序中以相同的方式进行操作时,一切都正常运行。 任何想法为什么它在这里不起作用?还是我应该使用后端需要的静态JSOn文件?

tyh775555 回答:JHipster应用程序内的类路径资源

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3148723.html

大家都在问