I am experiencing some confusion about the use and purpose of Spring DataBinder and ConversionService regarding binding of web requests to object modeling. This arose because I recently tried using the JSR-303 check by adding.
Before that I used:
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="mypackage.GlobalWebBindingInitializer" />
</property>
</bean>
This was good because I needed a global DataBinder that could be used by multiple controllers. The GlobalWebBindingInitialzer class implements several of them:
binder.registerCustomEditor(MyClass.class, new PropertyEditorSupport(MyClass.class)
However, I wanted to use the @Valid annotation and so added. A side effect of this is that the aforementioned AnnotationMethodHandlerAdapter bean is already defined as part of the annotation driven, so my global data binding is ignored.
So now I created this class:
public class MyClassConverter implements Converter<String, MyClass>
. , ?