假设我有两个项目:
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
请提出建议。欣赏。