Analysis of spring boot custom exception view process


This article mainly introduces the spring boot custom exception view process analysis, this article through the example code introduction is very detailed, for everyone’s study or work has a certain reference learning value, need friends can refer to

1、 Source code analysis

First look at the source code and then write your own custom exception view

The resolveerrorview() function first calls a function that returns modelandview. The required parameters of the function are a string of status codes and a set of maps, which are error messages

This is the function shown in the figure below

The above function determines whether you have provided a dynamic error page under templates / error /

If provided, directly return the view name and error information

If you don’t provide the figure below

Check again if there is a static error page

The above figure is the judgment logic of static error page


Return is a spring boot default several static page folder

Loop to find whether there is an error page in each folder

If the loop is not found, null is returned

2、 Custom exception view

If we want to customize our own exception view, we also override the resolveerrorview() function

However, we don’t need to write this cumbersome judgment any more. We just return a modelandview with the view name and error message

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.