简体   繁体   中英

Spring JUnit Test load properties of file outside of src/test/resources

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>

您可以尝试使用file:前缀

<value>file:/MyProject/MyModule/testData/testProperties.properties</value>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM