Spring applicationcontext. XML-[main method test]

Source: Internet
Author: User

General spring configuration file applicationcontext
. Xml
PATH is WEB-INF/

Or under SRC
However, when I use the main () function for testing:

// Put under webroot/WEB-INF, test

Applicationcontext
Act = new filesystemxmlapplicationcontext ("/webroot/WEB-INF/applicationcontext
. Xml
");

<!
-- Load spring injection for DWR -->
<Context-param>
<Param-Name> contextconfiglocation </param-Name>

<Param-value> classpath:/WEB-INF/applicationcontext. xml </param-value>
</Context-param>
<Listener>
<Listener-class>
Org. springframework. Web. Context. contextloaderlistener
</Listener-class>
</Listener>

You can also copy the configuration file to the src directory.

Applicationcontext
Act = new classpathxmlapplicationcontext ("applicationcontext
. Xml
");


<!
-- Load spring injection for DWR -->
<Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value> classpath: applicationcontext. xml </param-value>
</Context-param>
<Listener>
<Listener-class>
Org. springframework. Web. Context. contextloaderlistener
</Listener-class>
</Listener>

 

---------------------

For classpathxmlapplicationcontext ()
The default value is under the classpath path of the project.
Classpath:
Prefix is not required
If you want to use an absolute path, you must add file: prefix to indicate that this is an absolute path.

For filesystemxmlapplicationcontext ()
Two types are represented by default.
1. If there is no drive letter, yes
Project Working path, that is, the root directory of the project
2. A drive letter indicates the absolute file path.
To use the classpath path, you must prefix classpath:

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.