異常信息以下:java
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Date' to required type 'java.sql.Timestamp' for property 'wfsj'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.Date] to required type [java.sql.Timestamp] for property 'wfsj': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:463)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1097)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:882)
at org.springframework.flex.core.io.SpringPropertyProxy.setValue(SpringPropertyProxy.java:182)
at flex.messaging.io.amf.Amf3Input.readScriptObject(Amf3Input.java:438)
at flex.messaging.io.amf.Amf3Input.readObjectValue(Amf3Input.java:152)
at flex.messaging.io.amf.Amf3Input.readObject(Amf3Input.java:130)
at flex.messaging.io.amf.Amf3Input.readArray(Amf3Input.java:358)
…………
at flex.messaging.io.amf.AmfMessageDeserializer.readObject(AmfMessageDeserializer.java:227)
at flex.messaging.io.amf.AmfMessageDeserializer.readBody(AmfMessageDeserializer.java:206)
at flex.messaging.io.amf.AmfMessageDeserializer.readMessage(AmfMessageDeserializer.java:126)
at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:145)
at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:291)
at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCGLIB$$6f090fa2.service(<generated>)
at org.springframework.flex.servlet.MessageBrokerHandlerAdapter.handle(MessageBrokerHandlerAdapter.java:109)
…………
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.util.Date] to required type [java.sql.Timestamp] for property 'wfsj': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:264)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:448)
... 59 more
看異常信息大概知道屬性wfsj這個字段,不能完成java.util.Date 到 java.sql.Timestamp 日期時間戳的轉換。後面還有提示, 沒有找到匹配的conversion或editor。spring
conversion 在Spring中轉換對象屬性會用到,而editor和converter 以及formatter也是在轉換對象(String –> Date, String –> Timestamp),從字符串到對象,從對象到字符串的時候會常常用到。sql
解決方法:mvc
<bean id="customConfigProcessor" class="com.jp.tic.framework.flex.converter.CustomAmfConversionServiceConfigProcessor"/><flex:message-broker services-config-path="/WEB-INF/flex/services-config.xml"><flex:exception-translator ref="flexExceptionTranslator" /><flex:config-processor ref="configProcessor"/><flex:config-processor ref="customConfigProcessor"/><!--<flex:message-interceptor ref="flexMessageInterceptor" />
<flex:message-interceptor ref="loginMessageInterceptor" />-->
</flex:message-broker>爲message-broker對象注入CustomAmfConversionServiceConfigProcessor對象,CustomAmfConversionServiceConfigProcessor是繼承AbstractAmfConversionServiceConfigProcessor對象。app
AbstractAmfConversionServiceConfigProcessor對象中提供了對各個類型轉換serialization/deserialization的方法。ide
package com.jp.tic.framework.flex.converter;
import java.util.HashSet;
import java.util.Set;
import org.springframework.flex.core.io.AbstractAmfConversionServiceConfigProcessor;
/**
* <b>function:</b> 自定義AMF轉換服務
* @author hoojo
* @createDate 2013-7-17 下午01:35:12
* @file CustomAmfConversionServiceConfigProcessor.java
* @package com.jp.tic.framework.flex.converter
* @project JTZHJK-Server
* @blog http://blog.csdn.net/IBM_hoojo
* @email hoojo_@126.com
* @version 1.0
*/
public class CustomAmfConversionServiceConfigProcessor extends AbstractAmfConversionServiceConfigProcessor {private static Set<Class<?>> classes = new HashSet<Class<?>>();@Overrideprotected Set<Class<?>> findTypesToRegister() {
return classes;
}}
若是你還須要添加更多本身的轉化服務,那麼你須要給CustomAmfConversionServiceConfigProcessor 注入conversionService對象。flex
<!-- 添加配置類型轉換器、轉換服務 -->
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"><property name="converters"><list><bean class="com.jp.tic.framework.mvc.convert.StringToTimestampConverter"/><bean class="com.jp.tic.framework.mvc.convert.DateToTimestampConverter"/></list></property><property name="formatters"><list><bean class="com.jp.tic.framework.mvc.formatter.SimpleDateTimeFormatAnnotationFormatterFactory"/><bean class="com.jp.tic.framework.mvc.formatter.TimestampFormatterFactory"/></list></property></bean>
<bean id="customConfigProcessor" class="com.jp.tic.framework.flex.converter.CustomAmfConversionServiceConfigProcessor"><property name="conversionService" ref="conversionService"/></bean>