次のメソッドが必要です。
@ExceptionHandler(MyRuntimeException.class)
public String myRuntimeException(MyRuntimeException e, RedirectAttributes redirectAttrs){//does not work
redirectAttrs.addFlashAttribute("error", e);
return "redirect:someView";
}
私は得る:
java.lang.IllegalStateException: No suitable resolver for argument [1] type=org.springframework.web.servlet.mvc.support.RedirectAttributes]
からリダイレクトを実行する方法はあり@ExceptionHandler
ますか? または、この制限を回避する方法はありますか?
編集:
例外ハンドラーを次のように変更しました。
@ExceptionHandler(InvalidTokenException.class)
public ModelAndView invalidTokenException(InvalidTokenException e, HttpServletRequest request) {
RedirectView redirectView = new RedirectView("signin");
return new ModelAndView(redirectView , "message", "invalid token/member not found");//TODO:i18n
}
これは、例外をスローする可能性のあるメソッドです。
@RequestMapping(value = "/activateMember/{token}", method = RequestMethod.GET, produces = "text/html")
public String activateMember(@PathVariable("token") String token) {
signupService.activateMember(token);
return "redirect:memberArea/index";
}
変更した例外ハンドラーの問題は、次の URL に体系的にリダイレクトされることです。
http://localhost:8080/bignibou/activateMember/signin?message=invalid+token%2Fmember+not+found
それ以外の:
http://localhost:8080/bignibou/signin?message=invalid+token%2Fmember+not+found
編集2:
これが私の変更されたハンドラーメソッドです:
@ExceptionHandler(InvalidTokenException.class)
public String invalidTokenException(InvalidTokenException e, HttpSession session) {
session.setAttribute("message", "invalid token/member not found");// TODO:i18n
return "redirect:../signin";
}
私が今抱えている問題は、メッセージがセッションでスタックしていることです...