Spring-servlet.xml and Application.xml configuration locations and meanings in Web. xml

Source: Internet
Author: User

Spring-servlet.xml and Application.xml configuration locations and meanings in Web. XML2015-09-12 18:04 18451 People read comments (0) favorite reports Classification:Web. Xml (8)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

When we carry out spring-servlet development, often encounter configuration file configuration problem, to solve this problem thoroughly, we need to understand the basic architecture of SPRINGMVC design

The 1.SpringMVC configuration is divided into two parts application.xml and Spring-servlet.xml

2. Function and configuration location of two configuration files

2.1.application.xml: Corresponds to a system-level configuration that is scoped to the system context.

2.2.spring-servlet.xml: corresponding to the controller level configuration, the scope is the control layer context.

3. Their configuration in Web. xml

3.1. Because Application.xml is a system-level context, its initialization needs to be placed in the <context-param> tag in Web. XML, while other configuration files like scheduled tasks are initialized under this tab.

3.2. Since Spring-servlet.xml is only a controller-level context, it is plainly a servlet-level initialization that does not involve any entity other than forwarding, so its scope is limited to the servlet level only. So it should be initialized with spring's dispatcherservlet, so it's initialized in the <servlet> expression. It has a default value of "/web-inf/remoting-servlet.xml", note that the corresponding name of the configuration file is "Servlet-name"-servlet.xml, so if you do not give the servlet the location of the configuration file, And there is no configuration file in the default location, then the system starts with an error.


Note: For what should be initialized in the servlet configuration file, in addition to the resolution of the view, the location of the static resource file, the controller initialization mode, the other should not be placed in the servlet configuration file, it should only be responsible for the forwarding of the request, Parsing of the returned results and parsing of static resource files, initialization of other objects, scheduled tasks ... Should not be placed under this configuration file for management.


[HTML]View PlainCopy
    1. <? XML version= "1.0" encoding="UTF-8"?>
    2. <Web-app xmlns="Http://java.sun.com/xml/ns/javaee" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "
    3. xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
    4. Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "
    5. version= "3.0" metadata-complete="true">
    6. <!--This place defaults to the configuration files for system variables, which belong to the system level configuration- -
    7. <context-param>
    8. <param-name>contextconfiglocation</param-name>
    9. <param-value>
    10. Classpath:spring/application.xml.xml,
    11. Classpath:spring/spring-quartz.xml
    12. </param-value>
    13. </context-param>
    14. <context-param>
    15. <param-name>webapprootkey</param-name>
    16. <param-value>webapp.root</param-value>
    17. </context-param>
    18. <listener>
    19. <listener-class>org.springframework.web.util.webapprootlistener</listener-class >
    20. </Listener>
    21. <!-- <context-param>
    22. <param-name>logbackconfiglocation</param-name>
    23. <param-value>classpath:conf/logback.xml</param-value>
    24. </Context-param>-->
    25. <!-- <listener>
    26. <listener-class>xorg.springframework.web.util.logbackconfiglistener</ Listener-class>
    27. </Listener>-->
    28. <listener>
    29. <listener-class>com.cloudfarmhdapi.admin.listener.systemlistener</listener-class >
    30. </Listener>
    31. <!--This place loads the configuration files for the servlet's variables, which are configured at the controller level
    32. 1. If you do not configure the configuration file location for this servlet-context.xml,
    33. Then the default will go to the/web-inf/servlet-context.xml below to find this file
    34. 2. If this location is configured, it will go to the location to load the file
    35. -->
    36. <servlet>
    37. <servlet-name>appservlet</servlet-name>
    38. <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class >
    39. <init-param>
    40. <param-name>contextconfiglocation</param-name>
    41. <param-value>classpath:spring/servlet-context.xml</param-value>
    42. </init-param>
    43. <load-on-startup>1</load-on-startup>
    44. </servlet>
    45. <servlet-mapping>
    46. <servlet-name>appservlet</servlet-name>
    47. <url-pattern>/</url-pattern>
    48. </servlet-mapping>
    49. <!--charactor encoding --
    50. <filter>
    51. <filter-name>encodingfilter</filter-name>
    52. <filter-class>org.springframework.web.filter.characterencodingfilter</ Filter-class>
    53. <init-param>
    54. <param-name>encoding</param-name>
    55. <param-value>utf-8</param-value>
    56. </init-param>
    57. </Filter>
    58. <filter-mapping>
    59. <filter-name>encodingfilter</filter-name>
    60. <url-pattern>/*</url-pattern>
    61. </filter-mapping>
    62. <!--Shiro Security filter --
    63. <filter>
    64. <filter-name>shirosecurityfilter</filter-name>
    65. <filter-class>org.springframework.web.filter.delegatingfilterproxy</filter-class >
    66. <init-param>
    67. <param-name>targetfilterlifecycle</param-name>
    68. <param-value>true</param-value>
    69. </init-param>
    70. </Filter>
    71. <filter-mapping>
    72. <filter-name>shirosecurityfilter</filter-name>
    73. <url-pattern>/*</url-pattern>
    74. <dispatcher>request</Dispatcher>
    75. <dispatcher>forward</Dispatcher>
    76. <dispatcher>error</Dispatcher>
    77. </filter-mapping>
    78. <session-config>
    79. <session-timeout>60</session-timeout>
    80. </session-config>
    81. <welcome-file-list>
    82. <welcome-file>index.htm</welcome-file>
    83. </welcome-file-list>
    84. </Web-app>

Spring-servlet.xml and Application.xml configuration locations and meanings in Web. xml

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.