Applicationcontext.xml (the system cannot find the file specified)

Source: Internet
Author: User

caused By:java.io.FileNotFoundException:applicationContext.xml (the system cannot find the file specified)


Method One:

ApplicationContext context = new Classpathxmlapplicationcontext ("Applicationcontext.xml");

Applicationcontext.xml in src directory

Method Two:

ApplicationContext context = new Filesystemxmlapplicationcontext ("Src/applicationcontext.xml");

Applicationcontext.xml in src directory
And then Drivecar dc= (Drivecar) Ctx.getbean ("Drivecar"), you can use the ...
Note that the above two types of loading are paths.
Then convert them to beanfactory. The bean that needs to be used is obtained using Getbean (""), which can be either by ID or name.
There are two other ways to load:


Method Three: Classpathresource resource =  new  classpathresource ("Applicationcontext.xml");
Beanfactory factory =  New  xmlbeanfactory (Resource);  
Method Four:
Resource Resource =  new  filesystemresource ("Src/applicationcontext.xml");
Beanfactory factory =  New  xmlbeanfactory (Resource); The
also needs to be aware of the different paths above. In fact classpath the corresponding path is the SRC directory, and filesystem is relative to the project directory. So their path is different, load it carefully, otherwise it will be reported java.io.FileNotFoundException (the system can not find the specified file) of the exception.

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.