如何在Java中使用Spring读取属性文件

时间:2019-05-14 16:47:08

标签: java spring

我正在尝试读取属性文件“ migration.properties”以从中加载某些配置,但是却出现“找不到文件异常”。该文件位于src目录内的config文件夹中,并且我假设我在spring config文件中对其进行配置的方式是正确的。我也尝试给出完全限定的名称/config/migration.properties,但仍然是相同的问题。

enter image description here

Spring配置文件

<context:property-placeholder location="classpath:migration.properties" />

堆栈跟踪

Caused by: java.io.FileNotFoundException: class path resource [migration.properties] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:143)
at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:98)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:175)
at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:156)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:142)

0 个答案:

没有答案