究竟是server.error.path属性是什么?

时间:2018-07-18 11:12:28

标签: spring spring-boot configuration properties-file

在Spring Boot中,application.properties文件中server.error.path属性的用途是什么?

文档只是说:

  

错误控制器的路径

但是我想通过一个示例来清楚地描述此属性。

2 个答案:

答案 0 :(得分:1)

server.error.path-用作错误页面网址的一部分。

site.getBaseUrl() + "/error"

例如,在服务器端发生一些错误,您决定将用户重定向到错误页面,如下所示:

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/images/custom-error-page-aws-404-example.png

错误控制器的代码示例,您可以在这里找到:

https://www.logicbig.com/tutorials/spring-framework/spring-boot/implementing-error-controller.html

您可以在@RequestMapping("/error")中使用此属性。但是您可以使用"/error"

来代替"${server.error.path}"

更新:

此外,Spring Boot BasicErrorController使用server.error.path属性

答案 1 :(得分:0)

Spring Boot应用程序中的

属性server.error.path用于在处理自定义错误处理程序时定义错误路径。在Spring中,我们使用功能接口ErrorController创建了自定义错误处理程序,该接口具有String类型的方法getErrorPath,可帮助我们返回错误页面路径(我们的错误页面为视图)。 但是从Spring 2.3.0开始,此getErrorPath()方法已被弃用,并替换为server.error.path以管理错误路径。

例如server.error.path=/error

有关接口 ErrorController 的更多详细信息,请参阅ErrorController的Spring文档

相关问题