Spring cannot find the Applicationcontext.xml solution

Source: Internet
Author: User

The beginner spring is using resource rs=new classpathresource ("Applicationcontext.xml"), always encountered this error. Later found to use
ApplicationContext ctx=new filesystemxmlapplicationcontext ("Webcontent/web-inf/applicationcontext.xml") can solve this problem.
Carefully studied the following:
The reason why I can't find applicationcontext.xml in Classpathresource is because my XML file is placed under webcontent/web-inf/by default when I'm in construction. But using Classpathresource is in the current directory, which is where I'm looking for the Java file. So moving this XML file to my src directory is ok.
Similarly, if you are using ApplicationContext ctx=new classpathxmlapplicationcontext (), you are looking for the current path, the XML file should be in the current directory.
But if you use Filesystemxmlapplicationcontext, it is based on the specified path to find, so write the path complete. The XML path is now under the SRC folder. That will write: ApplicationContext ctx=new filesystemxmlapplicationcontext ("Src/applicationcontext.xml");
This is a relatively straightforward and simple notation, and later looked for the filesystemxmlapplicationcontext can also be used:
1. Add classpath: Prefix (this time the XML will be placed in the current directory is SRC)
ApplicationContext ctx=new filesystemxmlapplicationcontext ("Classpath:applicationContext.xml");
2. Add File: Write the path completely (use this method XML can be placed anywhere)
ApplicationContext ctx=new classpathxmlapplicationcontext ("ApplicationContext ctx=new Classpathxmlapplicationcontext ("File:f:/workspace/springexercis/src/applicationcontext.xml");
In summary, the simplest way is to honestly put XML under the SRC convenient.

Spring cannot find the Applicationcontext.xml solution

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.