While I was debugging my Spring Boot application I noticed that methods annotated with @InitBinder
are invoked for every incoming request.
@InitBinder("categories")
public void bindFields(WebDataBinder binder) {
binder.registerCustomEditor(Set.class, new CustomPropertyEditor());
}
In @InitBinder
methods we are setting a PropertyEditor
to a binder. I can't understand why should these methods be called again and again and set the same thing?
Does Spring create a new WebDataBinder
object for every single request?
It looks like this was answered in a post by Rossen Stoyanchev in the now defunct Spring Forums: https://web.archive.org/web/20181223143621if_/http://forum.spring.io/forum/spring-projects/web/55552-why-does-initbinder-method-get-called-multiple-times:
There was also this follow-up question: