解决方案 »

  1.   

    Spring 4.x是支持泛型注入的
      

  2.   

    属性上加上@DateTimeFormat(pattern="yyyy-MM-dd")
      

  3.   

    4.0.6的org.springframework.beans.factory.config.CustomEditorConfigurer类中customEditors为Map<Class<?>, Class<? extends PropertyEditor>>,属性值为Class类型,所以注入时会报错.
    官方文档中有两种注入方法
    1:
    //属性编辑类
    package example;public class ExoticTypeEditor extends PropertyEditorSupport {    public void setAsText(String text) {
            setValue(new ExoticType(text.toUpperCase()));
        }
    }
    //配置
    <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="customEditors">
            <map>
                <entry key="example.ExoticType" value="example.ExoticTypeEditor"/>
            </map>
        </property>
    </bean>2:
    //编辑器注册类
    package com.foo.editors.spring;public final class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {    public void registerCustomEditors(PropertyEditorRegistry registry) {        //注册编辑器实例
            registry.registerCustomEditor(ExoticType.class, new ExoticTypeEditor());    }
    }
    //配置
    <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="propertyEditorRegistrars">
            <list>
                <ref bean="customPropertyEditorRegistrar"/>
            </list>
        </property>
    </bean><bean id="customPropertyEditorRegistrar"
        class="com.foo.editors.spring.CustomPropertyEditorRegistrar"/>
      

  4.   

    这是bug,我也遇到了,没办法换成spring3了