java - (Spring) java.io.FileNotFoundException : class path resource cannot be opened because it does not exist 问题

标签 java spring

我想从类路径资源中获取属性文件 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/

相关文章:

java - H2 嵌入模式 - DELETE 命令给出 COLUMN NOT FOUND 错误

java : File. getAbsoluteFile().exists() 与 File.exists()

java - Spring + JAX.RS - 上下文加载两次

java - Spring Boot 应用程序中的特定属性不会被覆盖

spring - Singleton 是一种反模式吗?

java - Spring Security 3.2.0.RC1 - <http> 元素和弃用的方法

java - 使用一个类从头开始创建 jar

java - 如何正确编译 tostring 方法

java - 如何在actionListener(java)中共享变量

Spring MVC SessionAttributes 与 ModelAttribute 用法