关于springboot,使用ClassPathResource的线上大坑
问题: 本地通过ClassPathResource获取,然后来下载文件没什么问题,但是当打成jar包部署到线上之后,它居然一直报错,下载不了
原因代码:
ClassPathResource classPathResource = new ClassPathResource(user_template);
DownloadFileUtil.download(response,classPathResource.getFile(),false);
主要问题出现在classPathResource.getFile()
,在开发环境批示没有
修改代码:
ClassPathResource classPathResource = new ClassPathResource(user_template);
DownloadFileUtil.download(response,classPathResource.getInputStream(),"templ.xlsx",false);
将classPathResource.getFile()
改成classPathResource.getInputStream()
即可解决
可怜我的工具类得改一下