Nested exception is java. io. FileNotFoundException: class path resource [spring/spring-datasource-mog, nestedexception

Source: Internet
Author: User

Nested exception is java. io. FileNotFoundException: class path resource [spring/spring-datasource-mog, nestedexception

Problems found during spring unit testing:

Org. springframework. beans. factory. beanDefinitionStoreException: IOException parsing XML document from class path resource [spring/spring-datasource-mogon.xml]; nested exception is java. io. fileNotFoundException: class path resource [spring/spring-datasource-mogon.xml] cannot be opened because it does not exist
At org. springframework. beans. factory. xml. XmlBeanDefinitionReader. loadBeanDefinitions (XmlBeanDefinitionReader. java: 341)
At org. springframework. beans. factory. xml. XmlBeanDefinitionReader. loadBeanDefinitions (XmlBeanDefinitionReader. java: 302)
At org. springframework. beans. factory. support. AbstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 174)
At org. springframework. beans. factory. support. AbstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 209)
At org. springframework. beans. factory. support. AbstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 180)
At org. springframework. beans. factory. support. AbstractBeanDefinitionReader. loadBeanDefinitions (AbstractBeanDefinitionReader. java: 243)
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: 130)
At org. springframework. context. support. AbstractApplicationContext. obtainFreshBeanFactory (AbstractApplicationContext. java: 537)
At org. springframework. context. support. AbstractApplicationContext. refresh (AbstractApplicationContext. java: 451)
At org. springframework. context. support. ClassPathXmlApplicationContext. <init> (ClassPathXmlApplicationContext. java: 139)
At org. springframework. context. support. ClassPathXmlApplicationContext. <init> (ClassPathXmlApplicationContext. java: 83)
At com. test. db. mongo. test. Same test. setUp (same test. java: 32)
At junit. framework. TestCase. runBare (TestCase. java: 125)
At junit. framework. TestResult $1. protect (TestResult. java: 106)
At junit. framework. TestResult. runProtected (TestResult. java: 124)
At junit. framework. TestResult. run (TestResult. java: 109)
At junit. framework. TestCase. run (TestCase. java: 118)
At junit. framework. TestSuite. runTest (TestSuite. java: 208)
At junit. framework. TestSuite. run (TestSuite. java: 203)
At org. eclipse. jdt. internal. junit. runner. junit3.JUnit3TestReference. run (JUnit3TestReference. java: 130)
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)
Caused by: java. io. FileNotFoundException: class path resource [spring/spring-datasource-mogon.xml] cannot be opened because it does not exist
At org. springframework. core. io. ClassPathResource. getInputStream (ClassPathResource. java: 157)
At org. springframework. beans. factory. xml. XmlBeanDefinitionReader. loadBeanDefinitions (XmlBeanDefinitionReader. java: 328)
... 26 morez

The code for loading the configuration file is as follows:

ApplicationContext context = new ClassPathXmlApplicationContext ("spring/spring-datasource-mogon.xml ");

Previously, I encountered a similar problem when writing a unit test. There was no problem in querying, checking code, and loading methods, that is, the file could not be found in an error, and I was puzzled, I always thought it was related to the environment.

When debugging mongo today, I finally found the problem.

If a problem occurs: if the project is updated or refreshed, the above error is reported;

Solution:

1. Create a configuration file with the same content and different names; for example, change the name of the configuration file/spring-datasource-mogon.xml to/spring-datasource-mogon-1.xm

2. modify the code to load the configuration file: ApplicationContext context = new ClassPathXmlApplicationContext ("spring/spring-datasource-mogon-1.xml ");

3. debug and find that there is no such problem.


Summary:

1. After the project is updated, the unit test loaded project will also be refreshed. when the project is refreshed, the configuration file will be deleted from the project environment.

2. Modifying the name is equivalent to adding a new file, which will be synchronized in the project environment.

3. Therefore, the program can be found when loading new files, but the old one cannot be found.

4. The path of the configuration file loaded by the unit test is not found. If yes, you can directly add the old configuration file to it.

5. Legacy questions: when asked what refresh project, all configuration files will be cleared; how can this be avoided?

6. What is the difference between the editing and storage path of the project and the project running environment path.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.