spring4.0.6注入Date的属性编辑器无效 spring 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Spring 4.x是支持泛型注入的 属性上加上@DateTimeFormat(pattern="yyyy-MM-dd") 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"/> 这是bug,我也遇到了,没办法换成spring3了 最近老流鼻血,不知道怎么回事?是不是编程编多了啊? 网站流量过大,要加钱?如何减少流量 com.jspsmart.upload.jar无法下载中文文件,出现乱码 怎么在jsf中队隐藏变量赋值? 请教怎样捕获发帖内容中的url 怎么保证数据的一直性? 如何实现数据库连接和操作的bean源码 我们的网站正在测试,请大家多提意见 显示数据库列表 一个有关图片显示的问题?在线等待! esayui treegrid 刷新问题求解?????? java中catch异常后,再在catch块中重新抛出新异常系统无法捕获
官方文档中有两种注入方法
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"/>