最近在在使用@Value注入文件碰到如下问题:
工程在在IntelliJ IDEA开发环境里正常运行,但是一旦将工程打包成jar包运行,就报java.io.FileNotFoundException: class path resource错
代码如下:通过@Value将resource目录下test/billingconfig-file.xml目录注入到Resource上
@Value("classpath:test/billingconfig-file.xml")
private Resource resourceFile; // 注入计费点文件资源
JAXBContext context = JAXBContext.newInstance(BillingModelList.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
BillingModelList billingModelList = (BillingModelList) unmarshaller.unmarshal(resourceFile.getFile());
代码在IntelliJ IDEA开发环境里正常运行,但是一旦将工程打包成jar包运行,就提示如下错误:
java.io.FileNotFoundException: class path resource [test/billingconfig-file.xml] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/C:/Users/Administrator/Desktop/tmp/other/sp-bap-simulator-1.5.17.RELEASE.jar!/BOOT-INF/classes!/test/billin