加载应用程序上下文文件Bean.xml

时间:2016-03-19 16:05:19

标签: java spring

我想自定义现有的project。我可以毫无错误地构建和部署该项目。我的问题是如果我尝试加载我的BeanLocation.xml

 new ClassPathXmlApplicationContext("file:spring/config/BeanLocations.xml");

它会抛出错误:

class org.springframework.beans.factory.BeanDefinitionStoreException
IOException parsing XML document from URL [file:resources/spring/config/BeanLocations.xml]; nested exception is java.io.FileNotFoundException: resources/spring/config/BeanLocations.xml (No such file or directory)

如果你仔细看看我的类路径:

 C:/Program Files/Java/jdk1.8.0_60/lib/tools.jar;C:/Users/admin/workspace/ssf/samples/customcontroller/../../as-common/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../as-shared/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../commons-httpclient-contrib/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../gwt/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../indexer-lucene/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../jboss-portal/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../liferay/liferay/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../liferay-light/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../lucene-contrib/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../main/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../main-minimum/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../portal-module/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../remoting/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../rest-shared/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../slide-webdavclient/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../ssfs/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../taglib/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../tools/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../util/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../util-search/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/../../liferay/teaming/classes;C:/Users/admin/workspace/ssf/samples/customcontroller/src/resources

然后您会发现C:/Users/admin/workspace/ssf/samples/customcontroller/src/resources包含文件C:/Users/admin/workspace/ssf/samples/customcontroller/src/resources/spring/config/BeanLocation.xml

1 个答案:

答案 0 :(得分:0)

您正在使用file uri。这种uri并不关心类路径,而是读取相对于当前文件夹的文件。

使用classpath uri,或使用正确的路径设置file uri。