<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 註解開啓包掃描 -->
<context:component-scan base-package="com.qf.controller"></context:component-scan>
<!-- 配置Json解析器 -->
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
<!-- 配置事務解析器 -->
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!-- 將視圖名 渲染後視圖的前綴 -->
<property name="prefix" value="/"/>
<!-- 將視圖名 渲染後視圖的後綴 -->
<property name="suffix" value=".jsp"/>
</bean>
<!-- 上傳的解析器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 設置編碼的格式-->
<property name="defaultEncoding" value="utf-8"></property>
<!-- 設置文件的大小-->
<property name="maxUploadSize" value="1000000"></property>
</bean>
<!-- 開啓註解驅動,要想Controller正常訪問必須要有DefaultAnnotationHandlerMapping
與AnnotationMethodHandlerAdapter,這兩個bean默認是自動註冊的,
但是加了<mvc:resources>不會註冊,所以需要手動註冊,開啓註解驅動是一種簡便的開啓方法。 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 忽略靜態資源,靜態文件不需要由spring來處理 -->
<mvc:resources location="/js/*" mapping="/js/**"/>
<!-- spring處理不了的請求就交給default-servlet-name -->
<mvc:default-servlet-handler default-servlet-name="default"/>
<!-- 登錄攔截配置 -->
<!-- <mvc:interceptors>
<mvc:interceptor>
要攔截的
<mvc:mapping path="/**"/>
要忽略的
<mvc:exclude-mapping path="/user/loging"/>
攔截器的第二種配置攔截器的bean
<ref bean="logingInterceptor"/>
</mvc:interceptor>
</mvc:interceptors> -->
<!-- 全局異常處理 -->
<!-- <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
默認的錯誤頁面
<property name="defaultErrorView" value="error1"></property>
錯誤頁面可以通過ex變量訪問錯誤信息
<property name="exceptionAttribute" value="ex"></property>
定義需要特殊處理的異常,用類名或完全路徑名作爲key,異常頁面名字作爲值
<property name="exceptionMappings">
<props>
<prop key="java.lang.ArithmeticException">error2</prop>
</props>
</property>
</bean> -->
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 註解開啓包掃描 -->
<context:component-scan base-package="com.qf.controller"></context:component-scan>
<!-- 配置Json解析器 -->
<bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
<!-- 配置事務解析器 -->
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<!-- 將視圖名 渲染後視圖的前綴 -->
<property name="prefix" value="/"/>
<!-- 將視圖名 渲染後視圖的後綴 -->
<property name="suffix" value=".jsp"/>
</bean>
<!-- 上傳的解析器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 設置編碼的格式-->
<property name="defaultEncoding" value="utf-8"></property>
<!-- 設置文件的大小-->
<property name="maxUploadSize" value="1000000"></property>
</bean>
<!-- 開啓註解驅動,要想Controller正常訪問必須要有DefaultAnnotationHandlerMapping
與AnnotationMethodHandlerAdapter,這兩個bean默認是自動註冊的,
但是加了<mvc:resources>不會註冊,所以需要手動註冊,開啓註解驅動是一種簡便的開啓方法。 -->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 忽略靜態資源,靜態文件不需要由spring來處理 -->
<mvc:resources location="/js/*" mapping="/js/**"/>
<!-- spring處理不了的請求就交給default-servlet-name -->
<mvc:default-servlet-handler default-servlet-name="default"/>
<!-- 登錄攔截配置 -->
<!-- <mvc:interceptors>
<mvc:interceptor>
要攔截的
<mvc:mapping path="/**"/>
要忽略的
<mvc:exclude-mapping path="/user/loging"/>
攔截器的第二種配置攔截器的bean
<ref bean="logingInterceptor"/>
</mvc:interceptor>
</mvc:interceptors> -->
<!-- 全局異常處理 -->
<!-- <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
默認的錯誤頁面
<property name="defaultErrorView" value="error1"></property>
錯誤頁面可以通過ex變量訪問錯誤信息
<property name="exceptionAttribute" value="ex"></property>
定義需要特殊處理的異常,用類名或完全路徑名作爲key,異常頁面名字作爲值
<property name="exceptionMappings">
<props>
<prop key="java.lang.ArithmeticException">error2</prop>
</props>
</property>
</bean> -->
</beans>