添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In Spring Boot, what is the purpose of server.error.path property in application.properties file?

The documentation just says:

Path of the error controller

But I want a clear description of this property with an example.

For example some error happen on server side and you decide redirect user to error page like this:

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

Code example of error controller you can find here:

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

You can use this property in @RequestMapping("/error") . But instead of "/error" you can use "${server.error.path}"

UPDATE:

Also, Spring Boot BasicErrorController use server.error.path property

Property server.error.path in spring boot application used to define an error path while dealing with custom error handler. In Spring we create custom error handler using functional interface ErrorController , ths interface has a String type method getErrorPath which helps us to return the error page path(our error page as view). But from Spring 2.3.0 this getErrorPath() method has been deprecated and replaced with server.error.path to manage the error path.

e.g. server.error.path=/error

For more detail about interface ErrorController , please refer Spring doc for ErrorController

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .