@ControllerAdvice クラス内の @InitBinder アノテーション付きメソッドを使用して、グローバル InitBinder を登録しようとしています。
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());
}
}
私が抱えている問題は、ロード時に @InitBinder を見つけていることですが、「INIT BINDER」が System.out に出力されないため、実際にはメソッドに入らないことです。これは、カスタム エディターが登録されていないため、機能しないことを意味します。initBinder メソッドをコントローラの 1 つにコピー アンド ペーストすると、その特定のコントローラで問題なく動作します。
1989 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] (RequestMappingHandlerAdapter.java:636) - Detected @InitBinder methods in customInitBinder
ここで何が起こっているのですか?