现象:
编写了自定义类型转换器:StringToDateConverter
并在springmvc-config中进行了注册:
<!-- 注册自定义类型转换器 --> <mvc:annotation-driven enable-matrix-variables="true" conversion-service="conversionService" /> <!-- 自定义类型转换器 --> <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"> <property name="converters"> <list> <bean class="org.fkit.converter.StringToDateConverter" p:datePattern="yyyy-MM-dd"></bean> </list> </property> </bean>
从报错信息来看,我们自定义的转换器并没有成功注册
经过排查发现ConversionServiceFactoryBean不生效是因为受到了RequestMappingHandlerAdapter的影响!
<!-- 配置annotation类型的处理器适配器 --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="fastJsonHttpMessageConverter" /> <ref bean="xmlHttpMessageConverter" /> </list> </property> </bean>
把ConversionServiceFactoryBean的相关bean复制到RequestMappingHandlerAdapter的上面问题解决!