Good catch, this seems to be a new behavior with Spring 4.0+, your code works cleanly with Spring 3.2.x version.
The reason is because the customEditors type in CustomEditorConfigurer has changed using Spring 4.0+. If it is of type Map<String, ?> With Spring 3.2.x, then it is Map<Class<?>, Class<? extends PropertyEditor>> Map<Class<?>, Class<? extends PropertyEditor>> since Spring 4.0+.
The fix is ββto create your own PropertyEditorRegistrar instead, this way:
import java.text.SimpleDateFormat; import java.util.Date; import org.springframework.beans.PropertyEditorRegistrar; import org.springframework.beans.PropertyEditorRegistry; import org.springframework.beans.propertyeditors.CustomDateEditor; public class CustomDateEditorRegistrar implements PropertyEditorRegistrar { @Override public void registerCustomEditors(PropertyEditorRegistry registry) { registry.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), false)); } }
and use this in the configuration:
<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <property name="propertyEditorRegistrars"> <list> <bean class="dateeditor.CustomDateEditorRegistrar"/> </list> </property> </bean>
source share