<bean id="CustomEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="java.util.Date">
<bean class="com.dzc.DatePropertyEditor"></bean>
</entry>
</map>
</property>
</bean>
packet com.dzc
import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DatePropertyEditor extends PropertyEditorSupport { @Override
public void setAsText(String text) throws IllegalArgumentException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
Date d = sdf.parse(text);
this.setValue(d);
} catch (ParseException e) {
e.printStackTrace();
}
}

}报错原因:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CustomEditorConfigurer' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.LinkedHashMap] to required type [java.util.Map] for property 'customEditors'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [DatePropertyEditor] to required type [java.lang.String] for property 'customEditors[java.util.Date]': no matching editors or conversion strategy found
我看了CustomEditorConfigurer类的源码,发现customEditors属性的类型是Map<String,String>,是不是因为取出的Date类型的值无法放入Map的Value内导致的错误,而在spring2.0中运行时正常的,对比了CustomEditorConfigurer源码发现customEditors的Map类型没定义泛型。如果真是这样,那在Spring3.0中怎么写个Date类型的自定义属性编辑器啊,望各位大虾帮帮小弟,偶才刚刚开始学习spring,很多不懂,谢谢大家了。