Spring 整合 Flex (BlazeDS)无法从as对象 到 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.Ill

异常信息如下:

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。

conversion 在Spring中转换对象属性会用到,而editor和converter 以及formatter也是在转换对象(String –> Date, String –> Timestamp),从字符串到对象,从对象到字符串的时候会经常用到。

解决方法:

<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对象。

AbstractAmfConversionServiceConfigProcessor对象中提供了对各个类型转换serialization/deserialization的方法。

 

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<?>>();

    

    @Override

    protected Set<Class<?>> findTypesToRegister() {

        return classes;

    }

}

 

如果你还需要添加更多自己的转化服务,那么你需要给CustomAmfConversionServiceConfigProcessor 注入conversionService对象。

<!-- 添加配置类型转换器、转换服务 -->

    <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>

上一篇:PHP浮点数的一个常见问题的解答 (转载 http://www.laruence.com/2013/03/26/2884.html)


下一篇:当页面加载完成时,JQ触发添加页面的元素的事件触发不了。。