SpringMVC4.x配置JSON视图

<?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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:p="http://www.springframework.org/schema/p"
	default-autowire="byName" default-init-method="init"
	default-destroy-method="depose"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
		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">
	
	<!-- 组件自动扫描 -->      
    <context:component-scan base-package="com.runsun.bfc.loms.controller"/>  
    
    <!-- 消息转换器 -->
    <mvc:annotation-driven>
    	<mvc:message-converters register-defaults="true">
		    <!--  JSON转换器 -->
			<bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">			        
		        <property name="charset" value="UTF-8" />
		        <property name="supportedMediaTypes">
			        <list>				        
					    <value>text/html;charset=UTF-8</value>
					    <value>text/json;charset=UTF-8</value>
					    <value>application/json;charset=UTF-8</value>
			        </list>
			    </property>
			    <property name="features">
			    	<list>
			    		<value>WriteDateUseDateFormat</value>
			    	</list>
			    </property>
		    </bean>
    	</mvc:message-converters>    	
    </mvc:annotation-driven>
	
     
	<!-- 配置Velocity视图 -->
	<bean id="velocityConfigurer"
		class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
		<property name="resourceLoaderPath">
			<value>/WEB-INF/vm/</value>
		</property>
		<property name="velocityProperties">
			<props>
				<prop key="input.encoding">UTF-8</prop>
				<prop key="output.encoding">UTF-8</prop>
			</props>
		</property>
	</bean>
	<!-- 配置Velocity视图 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
		<property name="suffix">
			<value>.html</value>
		</property>
		<property name="contentType">
			<value>text/html;charset=utf-8</value>
		</property>
		<property name="exposeSessionAttributes">
			<value>true</value>
		</property>
		<!--日期工作类 -->
		 <property name="dateToolAttribute" value="dateTool"/>
		<!--数字工具类 -->
		 <property name="numberToolAttribute" value="numberTool"/>
		 <!--是否开放request属性--> 
		 <property name="exposeRequestAttributes" value="true" /> 
		 <!--request属性引用名称--> 
        <property name="requestContextAttribute" value="rc"/>       
	</bean>
	
    <!-- 文件上传配置注意:这里申明的id必须为multipartResolver -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    	<!-- 限制文件大小5M以内 -->
       <property name="maxUploadSize" value="5242880"/>
       <property name="defaultEncoding" value="UTF-8"/>
    </bean>
    
	<!-- 对静态资源文件的访问 -->
    <mvc:resources mapping="/js/**" location="/js/" cache-period="31556926" />         
    <mvc:resources mapping="/css/**" location="/css/" cache-period="31556926" />   
    <mvc:resources mapping="/easyui/**" location="/css/" cache-period="31556926" />   
    <mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/>
	<mvc:resources mapping="/fonts/**" location="/fonts/" cache-period="31556926"/>  
	  
	<!-- 配置拦截器 -->
	<mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="/**"/>
			<bean class="com.runsun.bfc.loms.interceptor.SecurityInterceptor">
				<property name="excludedUrls">
					<list>
                        <value>/login.html</value>                      
                        <value>/login.json</value>                       
                        <value>/Kaptcha.jpg</value>                       
                    </list>
				</property>
				<property name="excludedLoginUrls">
					<list>                        
                        <value>/noaccess.html</value>
                        <value>/index.html</value>                      
                        <value>/logout.html</value>
                        <value>/setPasswordPage.html</value>
                        <value>/setPassword.json</value>
                    </list>
				</property>
				<property name="loginPage" value="/login.html"/>
				<property name="noaccessPage" value="/noaccess.html"/>
			</bean>
		</mvc:interceptor>
	</mvc:interceptors>
	<!-- 使用切面注解 -->
	<aop:aspectj-autoproxy proxy-target-class="true"/>
</beans>


你可能感兴趣的:(SpringMVC4.x配置JSON视图)