简体   繁体   English

Spring JavaConfig:使用WebApplicationInitializer进行错误处理

[英]Spring JavaConfig: error handling with WebApplicationInitializer

I'm trying to handle errors such as Not Found (404), Acces Denied (403), Bad Request (400) etc. in Spring MVC web app. 我正在尝试处理Spring MVC Web应用程序中的错误,例如未找到(404),拒绝访问(403),错误的请求(400)等。

I use WebApplicationInitializer instead of web.xml to initialize my web app. 我使用WebApplicationInitializer而不是web.xml来初始化我的Web应用程序。 It would be simple to configure http errors handling in web.xml: 在web.xml中配置http错误处理很简单:

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

I found how to handle Acces Denied error only: How do I add an Access Denied Handler in spring-security-javaconfig 我发现仅如何处理Acces Denied错误: 如何在spring-security-javaconfig中添加访问拒绝处理程序

But is there any clear solution to handle http errors in web application initialized by WebApplicationInitializer? 但是,是否有任何明确的解决方案来处理由WebApplicationInitializer初始化的Web应用程序中的HTTP错误?

Unfortunately there is no error-page equivalent in java config servlet initialization. 不幸的是,java config servlet初始化中没有错误页面等效项。 You have to override it on application server level 您必须在应用程序服务器级别覆盖它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM