In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you two examples of springboot interceptor implementation of the analysis, I hope you will learn something after reading this article, let's discuss it!
The springboot interceptor executes twice
The reason is:
Org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error
It is also a controller path with / error
@ Configurationpublic class MVCConfig extends WebMvcConfigurationSupport {/ / Custom interceptor @ Bean public SecurityInterceptor getSecurityInterceptor () {return new SecurityInterceptor ();} @ Override public void addInterceptors (InterceptorRegistry registry) {/ / add interceptor InterceptorRegistration registration = registry.addInterceptor (getSecurityInterceptor ()); / / excluded path registration.excludePathPatterns ("/ login"); registration.excludePathPatterns ("/ logout") / / release this controller to registration.excludePathPatterns ("/ error"); / / intercept all registration.addPathPatterns ("/ *");}} Springboot interceptor principle
Based on the current request, find * * HandlerExecutionChain**** [all interceptors that can process the requested handler and handler]
Let's first sequentially execute the preHandle method of all interceptors
If the current interceptor prehandler returns as true. Then execute the preHandle of the next interceptor
If the current interceptor returns false. Directly reverse the afterCompletion of all interceptors that have been executed
If any interceptor returns false. Directly jump out of the non-execution target method
All interceptors return True. Execute the target method
Executes the postHandle methods of all interceptors in reverse order.
Any exception in the previous step will directly trigger afterCompletion in reverse order.
After the page is successfully rendered, afterCompletion will also be triggered in reverse order.
After reading this article, I believe you have a certain understanding of "sample Analysis of springboot interceptor execution twice". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.