Org. springframework. beans. factory. beandefinitionstoreexception: ioexception parsing XML document from class path resource [beans. XML]; Nested exception is Java. io. filenotfoundexception: Class path resource [beans. XML] cannot be opened because it does not exist
Java. Io. filenotfoundexception: Class path resource [Beans. xml] cannot be opened because it does not exist
At org. springframework. Core. Io. classpathresource. getinputstream (classpathresource. Java: 137)
At org. springframework. Beans. Factory. xml. xmlbeandefinitionreader. loadbeandefinitions (xmlbeandefinitionreader. Java: 167)
At org. springframework. Beans. Factory. xml. xmlbeandefinitionreader. loadbeandefinitions (xmlbeandefinitionreader. Java: 148)
At org. springframework. Beans. Factory. Support. abstractbeandefinitionreader. loadbeandefinitions (abstractbeandefinitionreader. Java: 128)
At org. springframework. Beans. Factory. Support. abstractbeandefinitionreader. loadbeandefinitions (abstractbeandefinitionreader. Java: 144)
At org. springframework. Context. Support. abstractxmlapplicationcontext. loadbeandefinitions (abstractxmlapplicationcontext. Java: 113)
At org. springframework. Context. Support. abstractxmlapplicationcontext. loadbeandefinitions (abstractxmlapplicationcontext. Java: 81)
At org. springframework. Context. Support. abstractrefreshableapplicationcontext. refreshbeanfactory (abstractrefreshableapplicationcontext. Java: 89)
At org. springframework. Context. Support. abstractapplicationcontext. Refresh (abstractapplicationcontext. Java: 262)
At org. springframework. Context. Support. classpathxmlapplicationcontext. <init> (classpathxmlapplicationcontext. Java: 87)
At org. springframework. Context. Support. classpathxmlapplicationcontext. <init> (classpathxmlapplicationcontext. Java: 72)
At org. springframework. Context. Support. classpathxmlapplicationcontext. <init> (classpathxmlapplicationcontext. Java: 63)
At inspur. democreen. Service. userservicetest. testadd (userservicetest. Java: 21)
At sun. Reflect. nativemethodaccessorimpl. invoke0 (native method)
At sun. Reflect. nativemethodaccessorimpl. Invoke (nativemethodaccessorimpl. Java: 39)
At sun. Reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. Java: 25)
At java. Lang. Reflect. method. Invoke (method. Java: 597)
At org. JUnit. Runners. model. frameworkmethod $1. runreflectivecall (frameworkmethod. Java: 44)
At org. JUnit. Internal. Runners. model. reflectivecallable. Run (reflectivecallable. Java: 15)
At org. JUnit. Runners. model. frameworkmethod. invokeexplosively (frameworkmethod. Java: 41)
At org. JUnit. Internal. Runners. Statements. invokemethod. Evaluate (invokemethod. Java: 20)
At org. JUnit. Runners. blockjunit4classrunner. runchild (blockjunit4classrunner. Java: 76)
At org. JUnit. Runners. blockjunit4classrunner. runchild (blockjunit4classrunner. Java: 50)
At org. JUnit. Runners. parentrunner $ 3.run( parentrunner. Java: 193)
At org. JUnit. Runners. parentrunner $1. Schedule (parentrunner. Java: 52)
At org. JUnit. Runners. parentrunner. runchildren (parentrunner. Java: 191)
At org. JUnit. Runners. parentrunner. Access $000 (parentrunner. Java: 42)
At org. JUnit. Runners. parentrunner $2. Evaluate (parentrunner. Java: 184)
At org. JUnit. Runners. parentrunner. Run (parentrunner. Java: 236)
At org. Eclipse. jdt. Internal. junit4.runner. junit4testreference. Run (junit4testreference. Java: 49)
At org. Eclipse. jdt. Internal. JUnit. Runner. testexecution. Run (testexecution. Java: 38)
At org. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. runtests (remotetestrunner. Java: 467)
At org. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. runtests (remotetestrunner. Java: 683)
At org. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. Run (remotetestrunner. Java: 390)
At org. Eclipse. jdt. Internal. JUnit. Runner. remotetestrunner. Main (remotetestrunner. Java: 197)
One is resolution, and the other is the beans. XML version.
Beanfactory applicationcontext = new classpathxmlapplicationcontext ("Beans. xml ");
The problem is prompted in this line. Take a closer look. No problem,
View help documentation
Beanfactory orApplicationcontext?
To put it simply:Unless you have a better reason, try to useApplicationcontextWhich of the following are more in-depth suggestions for "why" and so on?
ApplicationcontextIncludeBeanfactory. Recommended RatioBeanfactoryPriority, unless there are some restrictions, such as the size of the byte has a great impact on the memory (Applet). Then, the vast majority of "typical" enterprise applications and systems,ApplicationcontextIs what you need to use. Spring2.0 and later versions,LargeLink linkend = "beans-factory-extension-bpp">BeanpostprocessorExtended (for application proxy and other functions), if you chooseBeanfactoryTherefore, a considerable number of supported functions, such as transactions and AOP, cannot be used, which may lead to confusion because the configuration is correct.
So there is no error in this syntax. The problem is in beans. xml.
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <beans> </P> <p> <bean name = "U" class = "inspur. democreen. dao. impl. userdaoimpl "> <br/> </bean> </P> <p> <bean id =" userservice "class =" inspur. democreen. service. userservice "Singleton =" true "> <br/> <property name =" userdao "ref =" U "/> <br/> </bean> </P> <p> </beans> <br/>
At this point, the problem has come out. The xml configuration file and version of the spring container are inconsistent. spring1x and spring2x are written differently, and the jar used is spring2x, if the following error message is returned after you change the template, check whether your jar file is spring1x...
Spring2x template is provided here
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <beans xmlns = "http://www.springframework.org/schema/beans" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> </P> <p> <bean name = "U" class = "inspur. democreen. dao. impl. userdaoimpl "> <br/> </bean> <br/> <bean id =" userservice "class =" inspur. democreen. service. userservice "> <br/> <property name =" userdao "ref =" U "/> <br/> </bean> </P> <p> </beans> <br/>
OK. The problem is solved. Continue to learn about spring's IOC and AOP...