org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [bean1.xml]; nested exception is java.io.FileNotFoundException: class path resource [bean1.xml] cannot be opened because it does not exist错误现象
出现的错误是没有找到配置文件,打不开配置文件
可以去找配置文件的错误
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="user" class="Spring5.User"></bean>
</beans>
配置文件没有错误,可以寻找路径问题
public void testAdd(){
//1.加载spring配置文件
ApplicationContext context = new ClassPathXmlApplicationContext("Spring5/bean1.xml");
写路径的时候一定要写全路径