写第一个Spring应用报错 " ... class path resource [Beans.xml] cannot be opened because it does not exist "

之前是这样写的,然后报的错:
ApplicationContext context = new ClassPathXmlApplicationContext(“Beans.xml”);

将上述代码改成:
ApplicationContext con = new ClassPathXmlApplicationContext("/***/***/Beans.xml");

改成下面这样也是可以的:
AbstractApplicationContext con = new ClassPathXmlApplicationContext("/***/***/Beans.xml");

报这个错的原因就是找不到 Beans.xml 这个文件.

另外在学习创建 Spring 程序时,遇到的一个错误:
“Unsupported major.minor version 52.0”
这个错误的原因可能是,MyEclipse自带的Tomat版本跟JDK版本不对应导致的.
手动将项目改成JDK1.8 版本就好了.

报错:
"class path resource [Beans.xml] cannot be opened because it does not exist"

XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource(“Beans.xml”));
改成:
XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("/com/hujian/Beans.xml"));


ApplicationContext context = new FileSystemXmlApplicationContext(“Beans.xml”);
改成:
ApplicationContext context = new FileSystemXmlApplicationContext("…/SpringExample/src/com/hujian/Beans.xml");

你可能感兴趣的:(学习日记)