[JAVA] I want to know the Method of the Controller where the Exception was thrown in the ExceptionHandler of Spring Boot

1. What you want to do

--Set exception handling with ExceptionHandler --Know which method of which controller caused the exception

2. Version, conditions, etc.

3. What I did

--Add HandlerMethod handlerMethod to the parameter of the method annotated with ExceptionHandler

MyExceptionHandler.java



@ExceptionHandler(MyException.class)
public ResponseEntity<String> myExceptionHandler(
    MyException exception,
    HandlerMethod handlerMethod) {

    //abridgement
}

--See Javadoc for HandlerMethod -- getMethod () and getMethodAnnotation (java.lang.Class <A> annotationType) can be used

4. Document

end.

Recommended Posts

I want to know the Method of the Controller where the Exception was thrown in the ExceptionHandler of Spring Boot
I want to control the default error message of Spring Boot
05. I tried to stub the source of Spring Boot
I tried to reduce the capacity of Spring Boot
I want to know the answer of the rock-paper-scissors app
I want to expand the clickable part of the link_to method
I want to get the information of the class that inherits the UserDetails class of the user who is logged in with Spring Boot.
I want to control the maximum file size in file upload for each URL in Spring Boot
What I did in the migration from Spring Boot 1.4 series to 2.0 series
What I did in the migration from Spring Boot 1.5 series to 2.0 series
I want to change the value of Attribute in Selenium of Ruby
What to do when you want to know the source position where the method is defined in binding.pry
I was addicted to the roll method
[Spring Boot] I investigated how to implement post-processing of the received request.
I want to display images with REST Controller of Java and Spring!
Procedure to make the value of the property file visible in Spring Boot
I want to know the JSP of the open portlet when developing Liferay
I want to pass the argument of Annotation and the argument of the calling method to aspect
My memorandum that I want to make ValidationMessages.properties UTF8 in Spring Boot
I want to output the day of the week
The story of raising Spring Boot 1.5 series to 2.1 series
I want to var_dump the contents of the intent
I want to get the value in Ruby
Get the class name and method name of Controller executed by HandlerInterceptor of Spring Boot
Get the path defined in Controller class of Spring boot as a list
How to set environment variables in the properties file of Spring boot application
I was addicted to the NoSuchMethodError in Cloud Endpoints
Specify the encoding of static resources in Spring Boot
I want to call a method of another class
I want to embed any TraceId in the log
I checked asynchronous execution of queries in Spring Boot 1.5.9
I want to display the name of the poster of the comment
[Active Admin] I want to specify the scope of the collection to be displayed in select_box
How to use CommandLineRunner in Spring Batch of Spring Boot
[Rails] I want to display the link destination of link_to in a separate tab
I want to call the main method using reflection
I want you to put the story that the error was solved when you stabbed the charger in the corner of your head
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
[Rough commentary] I want to marry the pluck method
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
I want to control the display of the upper management navigation bar (Control menu) in Liferay 7 / DXP
I want to recreate the contents of assets from scratch in the environment built with capistrano
The story of raising Spring Boot from 1.5 series to 2.1 series part2
About the function of Spring Boot due to different versions
What I fixed when updating to Spring Boot 1.5.12 ・ What I was addicted to
I want to set the conditions to be displayed in collection_check_boxes
I want to change the log output settings of UtilLoggingJdbcLogger
I want to call a method and count the number
I want to use the sanitize method other than View.
I was addicted to the setting of laradock + VSCode + xdebug
I want to transition to the same screen in the saved state
[Ruby] I want to reverse the order of the hash table
I want to temporarily disable the swipe gesture of UIPageViewController
Use @ControllerAdvice, @ExceptionHandler, HandlerExceptionResolver in Spring Boot to catch exceptions
I want to simplify the conditional if-else statement in Java
Spring boot controller method memo
Rails was difficult, so I made something like a controller of Spring Framework to take a break
[Controller] I want to retrieve the numerical value of a specific column from the DB (my memo)
[Spring Boot] I want to add my own property file and get the value with env.getProperty ().