“错误页面"在Spring MVC JavaConfig webapp中进行配置?(没有web.xml) [英] "error-page" configuration in Spring MVC JavaConfig webapp? (no web.xml)

查看:56
本文介绍了“错误页面"在Spring MVC JavaConfig webapp中进行配置?(没有web.xml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何使用Java配置将错误页面"类型的配置添加到Spring MVC Web应用程序?(没有web.xml)?

How would I go about adding "error-page" type configurations to a Spring MVC webapp using Java config? (No web.xml)?

<error-page>
     <error-code>404</error-code>
     <location>/errors/404</location>
</error-page>

我想使用这样的配置(在Java Config中)将所有未捕获的Exception转发到特定的控制器方法.

I'd like to use a configuration like this (in Java Config) to forward all uncaught Exceptions to a specific controller method.

我希望避免@ControllerAdvice/@ExceptionHandler配置(它允许我创建一个处理所有错误的控制器方法),因为我希望Spring Security继续捕获Access Denied异常,其他任何异常都由我的代码处理.

I was hoping to avoid the @ControllerAdvice / @ExceptionHandler configuration (which allows me to create a controller method that would handle ALL errors) because I'd like Access Denied exceptions to continue to be caught by Spring Security, and just let any other exceptions get handled by my code.

似乎在这里提出了类似的问题:​​ Spring JavaConfig没有捕获PageNotFound吗?

It looks like a similar question was asked here: Spring JavaConfig is not catching PageNotFound?

推荐答案

查看 https://java.net/jira/browse/SERVLET_SPEC-50 -如果没有web.xml,则无法进行配置,但是您可以创建手动过滤器来为您做同样的事情.

look at https://java.net/jira/browse/SERVLET_SPEC-50 - it's not possible to configure that without web.xml, but you can create manual filter that will do same thing for you.

这篇关于“错误页面"在Spring MVC JavaConfig webapp中进行配置?(没有web.xml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆