类路径资源[aa.xlsx]无法解析为绝对文件路径,因为它不驻留在文件系统中

时间:2019-05-20 03:48:38

标签: java

我有问题。 当我解析xlsx文件时,java会抛出这样的错误。

java.io.FileNotFoundException: class path resource [template.xlsx] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/data0/webroot/triallesson-msg-iservice/triallesson-msg-iservice.jar!/BOOT-INF/classes!/template.xlsx ,message = class path resource [template.xlsx] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/data0/webroot/triallesson-msg-iservice/triallesson-msg-iservice.jar!/BOOT-INF/classes!/template.xlsx
2019-05-20 11:31:08.577 ERROR [springAppName_IS_UNDEFINED,,,] [TemplateController] -

但是我在本地调试时没有问题。一旦将jar上传到服务器,他就失败了

我将xlsx放在资源目录中。


    public void addTemplateByExcel() throws Exception {
        XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(ResourceUtils.getFile("classpath:template.xlsx")));
        XSSFSheet sheet = workbook.getSheetAt(0);

我该如何解决?

0 个答案:

没有答案