Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Spring中加载不在resources文件夹中的配置文件_Spring_Config - Fatal编程技术网

如何在Spring中加载不在resources文件夹中的配置文件

如何在Spring中加载不在resources文件夹中的配置文件,spring,config,Spring,Config,在我的Spring应用程序中,application.xml context:property-placeholder location="classpath:configuration.properties" 使用它我可以运行java代码 context = new ClassPathXmlApplicationContext("applicationContext.xml"); 但是,这要求我将configuration.properties文件放在resources文件夹中。相反,我希

在我的Spring应用程序中,application.xml

context:property-placeholder location="classpath:configuration.properties"
使用它我可以运行java代码

context = new ClassPathXmlApplicationContext("applicationContext.xml");
但是,这要求我将configuration.properties文件放在resources文件夹中。相反,我希望从应用程序外部化文件。如何配置application.xml以加载外部配置文件


谢谢

您必须使用绝对路径来满足您的需求

context:property-placeholder location="file:/path/to/configuration.properties"

尝试
文件:applicationContext.xml
。将尝试从当前目录加载文件

我建议使用
文件:config/applicationContext.xml
。然后,您可以为所有此类文件使用配置文件夹

现在,您需要一个启动脚本,将
cd
s放入安装应用程序的文件夹中