如何在Spring中加载不在resources文件夹中的配置文件
在我的Spring应用程序中,application.xml如何在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文件夹中。相反,我希
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放入安装应用程序的文件夹中