访问项目resource/static目录下的模板文件(解决Docker部署后访问不到的问题)

发布时间 2023-06-09 17:28:04作者: 小侯学编程

使用ClassPathResource方式获取static下的文件(别的方式本地可以访问到,Docker部署后不行)

final String templatePath = "/static/dbManage_Template.xlsx";
ClassPathResource resource = new ClassPathResource(templatePath);
InputStream inputStream = resource.getInputStream();

文件名称带中文(转码)

String path = FilePathConfig.gettempfilepath() + templateName + ".xlsx";
byte[] bytes = path.getBytes(StandardCharsets.UTF_8);
//保存的位置
File outFile = new File(new String(bytes));

Docker容器启动命令增加如下

-e LANG=C.UTF-8 -e LC_ALL=C.UTF-8 -e LANGUAGE=C.UTF-8