前段时间遇到一个配置文件的问题,记录下
项目路径图如下:
其中:默认包下面的TestIsolation类,为程序入口:代码如下:
public class TestIsolation {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml", TestIsolation.class);
I1Service s1 = (I1Service)ctx.getBean("service1");
//s1.f1();
//s1.f3();
s1.f5();
}
}
运行此类发现报错:Caused by: java.io.FileNotFoundException: class path resource [context.xml] cannot be opened because it does not exist
原因如下:ClassPathXmlApplicationContext的解释是
Create a new ClassPathXmlApplicationContext, loading the definitions from the given XML file and automatically refreshing the context.
This is a convenience method to load class path resources relative to a giv