The code inside Spring Web that handles @InitBinder
annotation does not make any
assumptions or requirements whether it is static or not.
The difference between static and non-static @InitBinder
method boils down to standard Java semantics of static and non-static methods, meaning the access to non-static variables and an ability to override the method.
If you do not need the instance variables or methods, you can safely make @InitBinder
method static, and also private.
Regardless of whether the @InitBinder
method static or not, it can be called multiple times per request, like at least once for each @PathVariable
, @RequestParam
, @RequestHeader
or @CookieValue
parameter of the request processing method. You can check the target bound to the WebDataBinder
object using WebDataBinder#getObjectName()
and customize the binder configuration based on that information.