【发布时间】:2013-09-03 19:02:42
【问题描述】:
假设我有两个项目:
ProjectA and ProjectB
ProjectA depends on ProjectB
我有一个 context.xml 位于 ProjectB/target/test-classes/context.xml。现在我需要从 ProjectA 中查找上下文。在 projectB 中,我有一个访问器类:
Class ContextAccessor{
ApplicationContext context = new
ClassPathXmlApplicationContext("context.xml");
public static ApplicationContext getContext(){
return context;
}
}
在 ProjectA 中,我尝试使用以下方法获取上下文:
ContextAccessor.getContext();
但它会抛出异常消息:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [context.xml]; nested exception is java.io.FileNotFoundException: class path resource [context.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at
请提出建议。欣赏。
【问题讨论】:
-
你是否将projectB中的类和资源添加到projectA的类路径中?
-
@SotiriosDelimanolis:不。如果我不想更改项目配置,我该怎么办?
标签: java spring classpath applicationcontext