SpringコントローラーBeanをセッションスコープに設定しています。次のようになります。
@Controller
@Scope(WebApplicationContext.SCOPE_SESSION)
@RequestMapping("/test")
public class SessionTestController implements Serializable {
private static final long serialVersionUID = -7735095657091576437L;
private transient Log log;
@PostConstruct
public void initialise() {
log = LogFactory.getLog(getClass());
}
@RequestMapping(method=RequestMethod.GET)
@ResponseBody
public String doGet() throws InterruptedException {
log.warn("This line will fail after deserialisation..."); // Causes NPE
}
}
@PostConstruct
Springは逆シリアル化後に呼び出さないようです。これにより、「log」フィールドがnullになり、doGet()
メソッドでNullPointerExceptionがスローされます。
通常、セッションスコープのBeanのロガーのようなシリアル化できないフィールドをどのように処理しますか?これを機能させるには、セッション対応のインターフェイスを実装する必要がありますか?