当junit4配置的test项目时,在重启后,target中的spring*.xml配置文件,会自动删除,debug时候会报错
Caused by:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/spring-dao.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/spring-dao.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
原因:target中的target文件里spring.xml被自动删除
解决办法:
1. 新建一个内容相同,名字不同的配置文件;例如,将配置文件/spring-dao.xml的名字修改为/spring-datasource-dao1.xm
2. 修改代码的加载配置文件为:ApplicationContext context = new ClassPathXmlApplicationContext("spring/spring-datasource-dao1.xml");
3. 修改名字,相当于添加了一个新的文件,这时工程环境中会跟着同步。