Original link: https://blog.csdn.net/evanxuhe/article/details/78650979
In order to unify exceptions, we usually define a unified management of all Exception, including custom Exception of ExceptionHandle
@ControllerAdvice intercept controller
@ExceptionHandler (value = Exception.class) intercept handle
Prior to use, but compiled a file on the Exception folder, tests found that the Controller does not work, but also abnormal jump in, no problem code is in line to see a lot of people have encountered this problem
So I looked, and sure enough there is no icon, recognized as the representative of a Bean Spring, Oh Oh. . . So not identify them
Then I put ExceptionHandle.java as before putting a single folder on Ok, on the other Contoller Service file folders and so on can be identified by the characteristics of the original folder is already possible to identify the bean
and so
As a @ControllerAdvice, ExceptionHandle.java to separate storage folders
Bean or existing folders, or files and other non-bean put together not identify them.
PS: There may be a class and not on the package the following items: For example, my project path: com.example.demo, and my exception class I did not notice package is built on the same level and under com directory
We must be careful of this pit! This experience for all of us to determine whether a class or interface as SpringBean identify and solve other problems are also very useful!
1) unrecognized ExceptionHandle, no
2) identification ExceptionHandle, there