Spring中报错之细节:Eception parsing XML document from class path resource

如何解决Spring中IOException parsing XML document from class path resource [spring-testAnnotationDemo.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-testAnnotationDemo.xml] cannot be opened because it does not exist的报错问题

 ##

Exception in thread “main” org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring-testAnnotationDemo.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring-testAnnotationDemo.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:614)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:515)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at spring_testAnnotationDemo.testMain.main(testMain.java:9)
Caused by: java.io.FileNotFoundException: class path resource [spring-testAnnotationDemo.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
… 13 more

解决办法如下:

首先检查一下你配置的XML文件路径在哪 当你看到这篇博客的时候,说明你的xml配置一文件并没有在你的项目src根目录下,而是在你自己创建的一个包下,那么这时候只需要在 ApplicationContext context = new ClassPathXmlApplicationContext(“spring-testAnnotationDemo.xml”); xml文件前面加上你的包名的路径,好了 问题解决。 ##

猜你喜欢

转载自blog.csdn.net/qq_36520235/article/details/79368144
今日推荐