Detailed explanation of spring-mvc.xml configuration file

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:websocket="http://www.springframework.org/schema/websocket"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
       http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
<!-- <mvc:annotation-driven /> will automatically register the DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter beans, which are required by spring MVC to distribute requests to @Controllers. It provides data binding support, support for reading json -->
    <mvc:annotation-driven />  
    <!-- Set the scanning scope of automatically injected beans, use-default-filters defaults to true, and will scan all java The class is injected, -->    
    <!-- Use-dafault-filters=”false” In the case: <context:exclude-filter> specified does not scan, <context:include-filter> specified scan -->
    < !-- Both springmvc and application files need to be configured, but mvc files only scan controller classes, application scans are not controller classes-->    
    <context:component-scan base-package="mytest.*" use-default-filters="false ">
        <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>


    <bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver" id="multipartResolver">
    <property name="defaultEncoding" value="UTF-8"/>
    </bean>
    <!-- ResourceBundleThemeSource is the default implementation class of ThemeSource interface -->
    <bean class="org.springframework.ui.context.support.ResourceBundleThemeSource " id="themeSource"/>
    <!-- Used to implement the theme selected by the user, which is stored on the client's machine as a cookie -->
    <bean class="org.springframework.web.servlet.theme.CookieThemeResolver " id="themeResolver" p:cookieName="theme" p:defaultThemeName="standard"/>
    
    <!-- due to request interception in web.xml file
    <servlet-mapping> 
<servlet-name>dispatcher</servlet-name> 
<url-pattern>/</url-pattern> 
</servlet-mapping> 
This will affect the acquisition of static resource files. The role of mvc:resources is to help you classify and complete the responsibility of acquiring static resources.
-->
    <mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />
    <!-- Configure to use SimpleMappingExceptionResolver to map exceptions -->
    <bean class="org.springframework .web.servlet.handler.SimpleMappingExceptionResolver" >
        <!-- Define the default exception handling page -->  
    <property name="defaultErrorView" value="error"/> 
         <!-- 
        The attribute value of the configuration exception is ex, then in the error page, you can get the exception information through ${exception}
        If this attribute is not configured, its default value is exception
         -->
        <property name="exceptionAttribute" value="exception"></property>
        <property name="exceptionMappings">
            <props>
            <!-- 映射特殊异常对应error.jsp这个页面 -->
                <prop key=".DataAccessException">error</prop>
                <prop key=".NoSuchRequestHandlingMethodException">error</prop>
                <prop key=".TypeMismatchException">error</prop>
                <prop key=".MissingServletRequestParameterException">error</prop>
            </props>
        </property>
    </bean>
    <!-- 配置jsp视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="jspViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value=""/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325759341&siteId=291194637