2016-11-10 46 views
0

我正在使用应用程序上下文来读取我的java类中的xml文件,但正确的xml文件没有加载。请帮助我。我在这里丢失了一些东西。使用ApplicationContext时未加载xml文件

,P:s时,也没有为XML文件,是不是才刚刚执行present.The线和控制移动到下一行抛出filenotfound错误

ApplicationContext appContext = null; 
appContext = new ClassPathXmlApplicationContext("classpath*:/ayifos.xml"); 

回答

0
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("ayifos.xml"); 

这将工作,如果您的ayifos.xml文件在src文件夹仅适用于独立应用程序。

0

只要你点到classpath作为一个地方(的classpath *:/ayifos.xml), 目录在您ayifos.xml是,必须在JVM类路径JVM启动时。在系统变量类路径中或在java命令行中输入-cp参数。

P.S.当然,如果你的应用程序打包成jar并从那里运行,那么ayifos.xml可以放在jar中。实际上,它是类路径*的地址的主要目的: