为了账号安全,请及时绑定邮箱和手机立即绑定

找不到properties

Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [src/main/resources/jdbc.properties] cannot be opened because it does not exist

properties和xml都放在源文件(main/java目录下)的resources目录下了

能读到xml

信息: Loading XML bean definitions from class path resource [spring-annotation.xml]
一月 07, 2017 3:29:50 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring-resource.xml]
一月 07, 2017 3:29:50 下午 org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
信息: Loading properties file from class path resource [src/main/resources/jdbc.properties]

但是后面就报错了。。。找不到这个文件

test类的classpath:spring-annotation.xml我是放在test目录下的resources目录下

上面两个在源文件下

测试类读取的xml在测试类自己的resources下

两个是分开的,我以为都是classpath。。。结果是不行的

正在回答

1 回答

src/main/resources/jdbc.properties改成:jdbc.properties

总体上可以这么写:classpath:jdbc.properties

0 回复 有任何疑惑可以回复我~
#1

未卜先知 提问者

我是配置文件就按classpath:jdbc.properties写的,但是读取文件的时候找不到 @ImportResource("classpath:spring-resource.xml") <context:property-placeholder location="classpath:jdbc.properties"/> 我把文件都放到test的resources下就好了(classpath:spring-annotation.xml我原来是放test下的) 上面两个我放源文件下了,结果这样不行
2017-01-07 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Spring入门篇
  • 参与学习       268773    人
  • 解答问题       963    个

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

进入课程

找不到properties

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信