我正在开发一个简单的 spring 项目;实际上尝试通过属性文件注入(inject)。我必须在 applicationContext.xml 文件中获取 prop 文件,它们不在同一目录下:
/src |_.com.luv2code.springdemo | |_sport.properties |_resources |_applicationContext.xml
尝试使用它,但无法找出正确的类路径
<context:property-placeholder location="classpath:/sport.properties"/>
最佳答案
- 应该是
src/main/com.luv2code...
,而不仅仅是src/com.luv2code...
。 - 斜杠表示类路径根,但您的资源似乎位于
com.luv2code.springdemo
包中。 - 将
sport.properties
放入资源目录:src/main/resources
。
关于java - Spring - java.io.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53951519/