I'm trying to register a global InitBinder using an @InitBinder annotated method inside a @ControllerAdvice class.
package com.myapp.spring.configuration;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@ControllerAdvice
@EnableWebMvc
public class CustomInitBinder {
@InitBinder
public void initBinder(WebDataBinder binder) {
System.out.println("INIT BINDER");
binder.registerCustomEditor(java.sql.Date.class, new SqlDatePropertyEditor());
binder.registerCustomEditor(java.sql.Timestamp.class, new SqlTimestampPropertyEditor());
}
}
The problem I'm having is that I see it finding the @InitBinder when loading, but it never actually enters the method because I don't get the "INIT BINDER" printed to System.out. This means that the custom editors aren't getting registered, and as such they don't work. If I copy and paste the initBinder method into one of my Controllers it works just fine for that specific Controller.
1989 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] (RequestMappingHandlerAdapter.java:636) - Detected @InitBinder methods in customInitBinder
Any ideas what's going on here?