SpringMVC 基本配置文件

时间:2022-12-10 21:39:41
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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"
>


<!--配置SpringMVC-->

<!--1.开启SpringMVC注解模式-->
<!--简化配置
1.自动注册DefaultAnnotationHandlerMappper,AnnotationMethodHandlerAdapter
2.提供一系列:数据绑定 数字和日期的format @NumberFormat,@DataTimeFormat,
xml/json默认读写支持.
-->

<mvc:annotation-driven/>

<!-- 2.静态资源默认servlet配置
1.对静态资源的处理
2.允许使用/做整体映射
-->

<mvc:default-servlet-handler/>

<!-- 3.配置jsp显示VideoResolver -->
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>

<!-- 4.扫描web相关的bean -->
<context:component-scan base-package="controller,intergrate.controller"/>

<!--extention:文件上传-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="102400000"/>
</bean>

<!--extention:json数据-->
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>

<!--extention:处理全局异常-->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.ArithmeticException">error</prop>
</props>
</property>
</bean>

<!--extention:自定义拦截器-->
<mvc:interceptors>
<bean class="interceptor.MyInterceptor"/>
</mvc:interceptors>

<!--extention:国际化-->
<!-- configure the locale resource -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="locale"/>
</bean>
<!--可以直接访问WEB-INF下的jsp页面-->
<mvc:view-controller path="/locale" view-name="locale"/>

</beans>