gpt4 book ai didi

java - 如何解决使用Spring加载.properties文件时找不到文件的问题?

转载 作者:行者123 更新时间:2023-12-01 06:02:17 25 4
gpt4 key购买 nike

我在使用Spring读取migration.properties时收到“FileNotFoundException”。

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

文件目录:迁移 -> src -> 配置

堆栈跟踪:

`Caused by: java.io.FileNotFoundException: class path resource [config/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)
... 8 more`

最佳答案

看起来迁移.properties 不在类路径中。您可以使用 file:/// 给出绝对路径并加载它。

关于java - 如何解决使用Spring加载.properties文件时找不到文件的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54596572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com