英文:
Spring JUnit Test load properties of file outside of src/test/resources
问题
我想将一个属性文件加载到Spring中,但是Spring无法在这个XML中找到该属性文件。
该文件位于 /MyProject/MyModule/testData/testProperties.properties
测试位于 /MyProject/MyModule/src/test/MyTest.java
如何让Spring从正确的路径加载?
<bean id="properties" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>testData/testProperties.properties</value>
</list>
</property>
</bean>
英文:
I want to load a properties file into Spring,but Spring cannot find the properties file with this XML.
The File is at /MyProject/MyModule/testData/testProperties.properties
The Test is at /MyProject/MyModule/src/test/MyTest.java
How to make Spring load from the correct path?
<bean id="properties" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>testData/testProperties.properties</value>
</list>
</property>
</bean>
答案1
得分: 1
你可以尝试使用 file:
前缀
<value>file:/MyProject/MyModule/testData/testProperties.properties</value>
英文:
You can try using file:
prefix
<value>file:/MyProject/MyModule/testData/testProperties.properties</value>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论