我想从类路径资源中获取属性文件 app.properties 。 原因是我正在使用maven构建jar文件。 jar 文件正在从 jar 内部获取属性。因此,其他人无法更改属性文件。
我希望属性文件是可配置的。
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>app.properties</value>
</list>
</property>
</bean>
工作正常,但是
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>"C:\\Temp\\app.properties"</value>
</list>
</property>
</bean>
不起作用。
是否可以将属性文件放置在目标文件夹中,以便 jar 可以从 jar 外部获取它?
最佳答案
尝试使用
<property name="location"><value>file:C:/Temp/app.properties</value></property>
关于java - (Spring) java.io.FileNotFoundException : class path resource cannot be opened because it does not exist 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7970315/