5
我想編寫一個彈簧命令行程序,該程序使用作爲命令行參數傳遞的屬性文件進行初始化。如何做到這一點?從命令行加載彈簧上下文屬性
啓動類:
public static void main (String [] args) {
String configFilename = args[0];
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"classpath:/context/applicationContext.xml");
MyBean bean = ctx.getBean(MyBean.class);
bean.getStarted();
}
的applicationContext.xml:
<context:property-placeholder location="CONFIGFILENAME" ignore-unresolvable="true"/>
如何獲取配置文件名了從我的主要方法,以實際Spring上下文,這樣我可以加載正確的環境依賴屬性?
您可以使用JVM參數代替: http://stackoverflow.com/questions/5598217/how-do-i-read-jvm-arguments-in-the-spring-applicationcontext-xml – DB5 2012-08-07 09:42:17