spring 4.1.5 到 4.3.5中defaultContentType 报错的解决

spring 4.1.5 到 4.3.5中 spring MVC 配置文件会 报 defaultContentType 为非法配置,解决方法就是参考下面的xml.

在原来的 ContentNegotiatingViewResolver 中加入 contentNegotiationManager,然后在contentNegotiationManager配置defaultContentType

<?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:util="http://www.springframework.org/schema/util"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    ">
	<!-- spring mvc related -->
	<!--
		JSR-303 support will be detected on classpath and enabled
		automatically
	-->
	<mvc:annotation-driven conversion-service="conversionService" />
	<mvc:default-servlet-handler />
	<!-- static resources -->
	<mvc:resources location="/static/" mapping="/static/**"
		cache-period="864000" /><!-- 24 * 3600 * 10 -->
	<!-- template view -->
	<bean id="velocityConfig"
		class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
		<property name="resourceLoaderPath" value="/WEB-INF/views/" />
		<property name="velocityProperties">
			<props>
				<prop key="input.encoding">UTF-8</prop>
				<prop key="output.encoding">UTF-8</prop>
				<prop key="contentType">text/html;charset=UTF-8</prop>
				<prop key="velocimacro.library">macro.vm</prop>
			</props>
		</property>
	</bean>

	<bean id="velocityViewResolver"
		class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
		<property name="layoutUrl" value="layout/default.vm" />
		<property name="cache" value="false" />
		<property name="suffix" value=".vm" />
		<property name="exposeSpringMacroHelpers" value="true" />
		<property name="dateToolAttribute" value="dateTool" />
		<property name="numberToolAttribute" value="numberTool" />
		<property name="contentType" value="text/html;charset=UTF-8" />
	</bean>

	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<bean
					class="org.springframework.http.converter.StringHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>text/html;charset=UTF-8</value>
						</list>
					</property>
				</bean>
			</list>
		</property>
	</bean>

	<bean id="contentNegotiationManager"
		class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
		<property name="mediaTypes">
			<value>
				html=text/html
				json=application/json
			</value>
		</property>
		<property name="defaultContentType" value="text/html" />
	</bean>
	<bean
		class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="order" value="0" />
		<property name="contentNegotiationManager" ref="contentNegotiationManager" />
		<property name="viewResolvers">
			<list>
				<ref bean="velocityViewResolver" />
			</list>
		</property>
		<property name="defaultViews">
			<list>
				<!-- <ref bean="velocityViewResolver"/> 	-->
			</list>
		</property>		
	</bean>
	
	<!-- file upload related -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding" value="UTF-8" />
		<property name="maxUploadSize" value="5000000" />
	</bean>
	
	<bean id="conversionService"
		class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
		<property name="formatterRegistrars">
			<bean class="com.letv.common.web.springmvc.converter.DefaultFormatterRegistrar" />
		</property>
	</bean>
	
	<context:component-scan base-package="com.letv.ofc.controller" />
     <!-- 	i18n start -->
	<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basenames">
			<list>
				<value>classpath:/i18n/messages</value>
			</list>                   
		</property>
		<property name="useCodeAsDefaultMessage" value="false" />
		<property name="defaultEncoding" value="UTF-8" />
		<property name="cacheSeconds" value="3" />
	</bean>
	<mvc:interceptors>
		<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
	</mvc:interceptors>
	<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" >
	  <property name="defaultLocale" value="${profile.language.default.locale}"/>
	</bean>
   <!-- i18n end -->   
<!--     comment out the below lines if not usa OA systems -->
<!-- 	<context:property-placeholder location="classpath*:conf/authen.properties"  ignore-unresolvable="true"/> -->
<!-- 	<import resource="classpath*:spring/spring-config-authen.xml" /> -->
</beans>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值