【发布时间】:2017-01-10 15:51:19
【问题描述】:
我正在尝试从 jar 文件外部导入 spring config.xml。有一个注解配置类可以导入到配置中
@Configuration
@ImportResource("file:config.xml")
public class SpringConfig {
...
}
来自 spring 的日志消息表明它找不到 config.xml。但他们没有说搜索此 config.xml 的路径是什么。
Caused by: java.io.FileNotFoundException: config.xml (The system cannot find the file specified)
在开发环境中
src\main\java\
|__com.packagewithclasses
|__config.xml
|__log4j.xml
在现场环境中
folder_holding_jars_and_configs
|__executable_jar_file.jar
|__config.xml
|__log4j.xml
我已经尝试过文档、谷歌、一些通配符、日志等。没有运气。 jar文件外配置相对路径的spring的起始路径是什么?
【问题讨论】:
-
您几乎不应该使用文件:对于资源,所有资源都应该从类路径加载。这确保它可以在每台开发人员机器上运行,并且在从 maven/gradle 构建时。
标签: java spring configuration relative-path