The application of spring in web development

Source: Internet
Author: User

(1) To use spring in a Web project, you need to import a jar package:
Spring-web-4.2.4.jar Bag
(2) Configuring Listener in the Web. xml file

1 <listener>2     <listener-class>3     org.springframework.web.context.ContextLoaderListener4     </listener-class>5 </listener>

This contextloaderlistener it implements the Servletcontextlistener. In this listener, when the server is started, the object is ApplicationContext, In fact, it is an implementation of the class Webapplicationcontext, the object is deposited into the ServletContext.
(3) We also need to configure the location of the Applicationcontext.xml file in the Web. xml file, which is found by default in the Web-inf directory Applicationcontext.xml
If the Applicationcontext.xml file is not in the default location, we can configure it in the Web. xml file.

1 <context-param>2     <param-name>contextconfiglocation</param-name>3     <param-value >classpath:applicationcontext.xml</param-value>4 </context-param>

Classpath:applicationContext.xml it represents the current project under the Classpath (which can be understood to be in SRC) down to find the Applicationcontext.xml file.
Contextconfiglocation It is a constant declared in listener that describes the location of the spring configuration file.
With the above configuration, the spring framework can be used in web development.

The application of spring in web development

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.