有人可以解释一下如何在静态资源下读取 jrxml 作为输入流吗?
这是我重新注册的资源路径
registry.addResourceHandler("/resources/**").addResourceLocations("WEB-INF/resources/");
在资源下我有reports文件夹,在reports文件夹下我有samplereport.jrxml
我使用这些代码,但它总是抛出 filenotfound 异常
Resource resource = new ClassPathResource("/reports/samplereport.jrxml");
InputStream resourceInputStream = resource.getInputStream();
我尝试了这个并将我的samplereport.jrxml移动到我的类的同一路径并且它工作了。
InputStream employeeReportStream
= this.getClass().getResourceAsStream("/samplereport.jrxml");
但我不想以这种方式工作。预先感谢您。
最佳答案
删除报告前的斜杠,如下面的代码。
Resource resource = new ClassPathResource("reports/samplereport.jrxml");
请参阅下面的 URL,了解有关加载文件的更多信息。
https://www.mkyong.com/java/java-read-a-file-from-resources-folder/
关于java - 在我的 spring 静态资源上读取文件始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51302591/