spring_mvc基本配置

<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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

	<context:component-scan base-package="dao,handler,inteceptor"></context:component-scan>
	
	<!-- 配置视图解析器 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
	
	
	<!-- 直接转发到页面,不经过handler -->
	<!-- <mvc:view-controller path="/hello" view-name="abc"/> -->
	
	
	<!-- 加载静态资源时需要配置,例如加载jquery.js ,这时普通请求会报404,需要配置mvc:annotation-driven-->
	<mvc:default-servlet-handler/>
	
	<mvc:annotation-driven></mvc:annotation-driven>
	
	<!-- 国际化资源文件 -->
	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
		<property name="basename" value="i18n"></property>
	</bean>
	
	<!-- 文件上传 -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding" value="UTF-8"></property>
		<!-- 设置上传文件大小,单位是字节 -->
		<property name="maxUploadSize" value="2048000000"></property>
	</bean>
	
	<!-- 配置自定义拦截器 -->
	<mvc:interceptors>
		<!-- 对所有请求配置拦截器 -->
		<bean class="interceptor.FirstInterceptor"></bean>
		
		<!-- 针对某一个请求配置拦截器 -->
		<mvc:interceptor>
			<mvc:mapping path="/emps"/>
			<bean class="interceptor.SecondInterceptor"></bean>
		</mvc:interceptor>
	</mvc:interceptors>
	
	<!-- 配置SimpleMappingException处理异常 -->
	<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
		<property name="exceptionAttribute" value="ex"></property>
		<property name="exceptionMappings">
			<props>
				<prop key="java.lang.ArrayIndexOutOfBoundsException">forward:/index.jsp</prop>
			</props>
		</property>
	</bean>
</beans>

你可能感兴趣的:(spring_mvc基本配置)