すべての404エラーを処理し、正しいページにスマートにリダイレクトするコントローラ(または他のコンポーネント)が必要です(これはテーブルsrc/targetに基づいています)。私は次のことを行ったので、私は、コントローラからスローされた例外処理に関するいくつかの質問を発見した:SpringブートWebアプリケーション - リダイレクトコントローラ
-
:
@ControllerAdvice
public class ServiceExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(Throwable.class)
@ResponseBody
ResponseEntity<String> handleControllerException(HttpServletRequest req, Throwable ex) {
String slug = req.getRequestURI(); // this is the URL that was not found
URI location=null;
try {
// lookup based on slug ...
location = new URI("http://cnn.com"); // let's say I want to redirect to cnn
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setLocation(location);
return new ResponseEntity<String>("Page has permanently moved", responseHeaders, HttpStatus.PERMANENT_REDIRECT);
}
}
私は、他の設定を行っていないこれで
二つの問題がある変更
"キャッチオール"のようなものを実装する方法に関するアイデアはありますか?
http://stackoverflow.com/questions/28902374/spring-boot-rest-service-exception-handling –