项目场景:B站尚硅谷Spring开发教程
哔哩哔哩视频网站。尚硅谷Spring开发教程第一节初创项目。
问题描述
简单Spring测试IOC创建实体bean。报错
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [src/bean1.xml]; nested exception is java.io.FileNotFoundException: class path resource [src/bean1.xml] cannot be opened because it does not exist
public class TestSpring5 {
@Test
public void testadd(){
ApplicationContext context = new ClassPathXmlApplicationContext("src/bean1.xml");
User user = context.getBean("user", User.class);
System.out.println(user);
user.add();
}
}
这个问题涉及到资源加载方面的知识。且大致可归为一类。就是加载文件找不到。
就我个人犯的错误而言。上图。