I have 5 controllers and i would like to register an InitBinder
to all of them.
I know i can add this code to each of them.
@InitBinder
public void initBinder(WebDataBinder binder)
{
binder.registerCustomEditor(StringWrapper.class, new StringWrapperEditor());
}
But i would like to define it only once (even create a bean of StringWrapperEditor
and use it instead of creating new every time.)
I searched SO and some other places but didn't find any answear. Is it even possible?
Im using spring 3.1.1 with java 1.6.
Implement a
PropertyEditorRegistrar
which registers all your customPropertyEditors
. Then in your configuration add aConfigurableWebBindingInitializer
which you hookup with the createdPropertyEditorRegistrar
and hook it to yourHandlerAdapter
.If you have a
<mvc:annotation-driven />
tag in your configuration, the problem is that with this tag you cannot add theWebBindingInitializer
to the adapter next to that there is already aConfigurableWebBindingInitializer
added to the pre-configured HandlerAdapter. You can use aBeanPostProcessor
to proces and configure the bean.Requires a bit of work but it is doable. You could also implement your own
WebBindingInitializer
.If you don't have the tag you can simply manually configure a
RequestMappingHandlerAdapter
and wire everything together.Links