互联网网站建设公司,中国建筑师室内设计网,网页美工设计实训中职期末试卷,公司网页如何建立一、Spring Boot打成jar包后#xff0c;resources目录下的资源文件获取不到
1.1、问题描述 在做公司业务开发时#xff0c;有一个地方是使用EasyExcel模板技术进行文件上传#xff0c;测试环境是OK的#xff0c;但是和前后端联调验证测试通过后#xff0c;上传到生产环境…一、Spring Boot打成jar包后resources目录下的资源文件获取不到
1.1、问题描述 在做公司业务开发时有一个地方是使用EasyExcel模板技术进行文件上传测试环境是OK的但是和前后端联调验证测试通过后上传到生产环境就不行了后来也是花费了很多时间才找出其中的问题以下为解决方案。 1.2、pom里边添加如下配置
build!-- 定义包含这些资源文件能在jar包中获取这些文件 --resourcesresourcedirectorysrc/main/java/directoryincludesinclude**/*.properties/includeinclude**/*.xml/includeinclude**/*.yml/include/includes!--是否替换资源中的属性--filteringfalse/filtering/resourceresourcedirectorysrc/main/resources/directoryincludesinclude**/*.*/include/includes!--是否替换资源中的属性--filteringfalse/filtering/resource/resources
/build
1.3、修改加载资源文件的方式
// 加载资源文件方式1
ClassPathResource classPathResource new ClassPathResource(static/budgetunit/employee_budget_unit_export.xlsx);
String templatePath classPathResource.getPath();// 加载资源文件方式2推荐
InputStream inputStream this.getClass().getClassLoader().getResourceAsStream(static/budgetunit/employee_budget_unit_export.xlsx);
String templatePath ClassLoader.getSystemResource(templates/budgetunit/employee_budget_unit_export.xlsx).getPath();