class path resource [quartz.properties] cannot be opened because it does not exist

待我称王封你为后i 2023-05-29 05:09 252阅读 0赞

从公司 SVN上更新了代码之后,运行一个spring boot项目,死活不能成功。以前可以。错误很多很吓人,但干货是这一句:

class path resource [quartz.properties] cannot be opened because it does not exist

从错误提示来看,很明显,说找不到配置文件“quartz.properties”,但明明就是有的啊。

在这里插入图片描述

  1. // 指定quartz.properties,可在配置文件中配置相关属性
  2. @Bean
  3. public Properties quartzProperties() throws IOException {
  4. PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
  5. propertiesFactoryBean.setLocation(new ClassPathResource("/config/quartz.properties"));
  6. propertiesFactoryBean.afterPropertiesSet();
  7. return propertiesFactoryBean.getObject();
  8. }

我目前为止,还是个JAVA白痴,于是又开始了寻寻觅觅的瞎琢磨过程。最后发现,代码没有问题,原因是编译结果里,没有将这个配置文件带过去。也就是,存放编译结果所在的文件夹target里,不知道为什么没有将这个配置文件拷贝过去。原来,提示找不到文件,不是看你代码里有没有,真正要看的,是编译结果啊。

在这里插入图片描述
解决办法:
将项目rebuild一次,再运行,就正常了。原因我估计是不知道为什么,这个文件可能被占用了,之前的运行过程中,一直拷贝失败。

发表评论

表情:
评论列表 (有 0 条评论,252人围观)

还没有评论,来说两句吧...

相关阅读