在我的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文件?