如何在Spring项目的Deployed Resources / web-resources /中使用属性文件

时间:2019-05-30 16:56:33

标签: java spring integration-testing properties-file

我正在开发一个春季项目,并且正在尝试进行集成测试,但是当我运行测试时,@ContextConfiguration(locations = {"file:src/main/webapp/WEB-INF/spring-servlet.xml"})使用一个.properties文件作为数据源,但是它说找不到web-resources/META-INF中的.properties文件,因为它总是尝试在webapp/META-INF中查找。

我在Java8中使用springframework 5.1.7,在集成测试中,我使用@ContextConfiguration(locations = {"file:src/main/webapp/WEB-INF/spring-servlet.xml"})指定应用程序上下文文件,并且在该文件中,我尝试在{{1 }},但是当我运行测试时找不到文件。

web-resources/META-INF
@RunWith(SpringRunner.class)
@ContextConfiguration(locations = {"file:src/main/webapp/WEB-INF/spring-servlet.xml"})
@WebAppConfiguration
public class OtrasAdicionalesControllerTest {
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="/META-INF/jdbc.properties" />
</bean>   

1 个答案:

答案 0 :(得分:1)

尝试替换

 "/META-INF/jdbc.properties"

"classpath:jdbc.properties"