與SpringSecurity的配置相似,spring一樣爲咱們提供了一個實現類WebMvcConfigurationSupport和一個註解@EnableWebMvc以幫助咱們減小bean的聲明。java
applicationContext-MvcConfig.xmlweb
- <context:component-scan base-package="web.function"
- use-default-filters="false">
- <context:include-filter type="annotation"
- expression="org.springframework.stereotype.Controller" />
- </context:component-scan>
-
-
-
-
-
- <bean id="viewResolver"
- class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="/WEB-INF/views/jsp/function/" />
- <property name="suffix" value=".jsp" />
- </bean>
-
-
- <bean id="messageSource"
- class="org.springframework.context.support.ResourceBundleMessageSource"
- p:basename="config.messages.messages">
- </bean>
-
-
- <bean id="servletHandlerAdapter"
- class="org.springframework.web.servlet.handler.SimpleServletHandlerAdapter" />
-
-
- <bean id="multipartResolver"
- class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
- p:defaultEncoding="UTF-8" />
-
-
- <bean id="exceptionResolver" class="web.core.CP_SimpleMappingExceptionResolver">
- <property name="defaultErrorView" value="common_error" />
- <property name="exceptionAttribute" value="exception" />
- <property name="exceptionMappings">
- <props>
- <prop key="java.lang.RuntimeException">common_error</prop>
- </props>
- </property>
- </bean>
-
-
-
- <bean id="initInterceptor" class="web.core.CP_InitializingInterceptor" />
-
-
-
-
-
- <bean id="localeResolver"
- class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
-
-
- <bean id="localeChangeInterceptor"
- class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
-
-
-
- <mvc:interceptors>
- <ref bean="localeChangeInterceptor" />
- <ref bean="initInterceptor" />
- </mvc:interceptors>
-
-
-
-
-
- <bean
- class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
- <property name="webBindingInitializer">
- <bean class="web.core.CP_PropertyEditorRegistrar">
- <property name="format" value="yyyy-MM-dd"></property>
- </bean>
- </property>
- <property name="messageConverters">
- <list>
- <bean
- class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
- <bean
- class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
- </list>
- </property>
- </bean>
-
-
- <!-- 會自動註冊RequestMappingHandlerMapping與RequestMappingHandlerAdapter
- 兩個bean,是spring MVC爲@Controllers分發請求所必須的。 並提供了:數據綁定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,讀寫XML的支持(JAXB),讀寫JSON的支持(Jackson) -->
- <mvc:annotation-driven />
-
-
-
- <mvc:resources mapping="/static/**" location="/WEB-INF/static/" />
MvcConfig.javaspring