Hello Sir, This is the first video of yours that I have watched, and I immediately subscribed to your channel because I was so impressed with the way you explain and the topics you cover. Today, for the second time, an interviewer asked me about interceptors, and I didn't have a single line of response. However, after watching your video and practicing as you explained, I can now confidently discuss this topic and implement it in my projects as well. I really want to thank you for explaining such an important topic on a free platform. The clarity of your explanation reflects your deep knowledge and experience. Please continue to post content like this, which is rarely found on TH-cam. Once again, thank you so much, sir. 🙏
Very good explanation and demo. Expecting more videos from you on spring and springboot. It would help many budding developers like me if you put videos on explaining any real time project or build any small features of application in the similar way. Thank you so much for this video.
Good explanation, very informative video, many people dont know about these topics, please keep posting these kind of topics which most of the other youtubers does not cover.
Excellent Explaination. Simple and straight to the point. Keep posting videos that could help the Java community. But I have doubt like whatever the examples that you have demonstrated can be achieved via servlet filters. Better if you would have explained with some example where using Interceptor gives an edge over the Servlet Api
Please make a detailed video on Spring Boot basics, like is it mandatory to have main method in an spring boot app to start the application, if not, then how will the SpringApplicaitonCOntext be initialised looking forward for more spring content from you
Read this on my blog: stacktips.com/articles/how-to-use-interceptor-in-spring-boot Source code: github.com/StackTipsLab/spring-boot-tutorials/tree/main/spring-interceptor
Very nice demonstration. Can this strategy be used to log the incoming and outgoing json payload as well? Do you have any demonstration for logging the payloads. For example, when a post end point is invoked by the client, I want to log the json payload (request) sent by the client and the json payload (response) sent back to the client.
Absolutely. interceptor can be used for logging request/response. But depending on the type of http client you use, you may not need to write any custom interceptor just for logging. Can I know which http client you intent to use?
@@TheTechMojo Thanks for reply. The scenario I am dealing with is as follows: There is a spring boot rest api application that has exposed "get" and "post" endpoints. My requirement is to log the incoming request and outgoing response when these endpoints are called by any client. The client may be Postman or even an another rest api may call these 2 endpoints. The reason I am asking this question is because I have read that once interceptor has read the incoming request, the request is considered to have been consumed and hence controller will not receive any request at all and throw exception.
Alright. That's pretty simple. Check out this example. github.com/StackTipsLab/spring-boot-tutorials/blob/main/spring-interceptor/src/main/java/com/stacktips/interceptors/LogHandlerInterceptor.java
The preHande() method is called before the request reaches the controller. If you have multiple interceptors, you can order them using the @Order annotation. All interceptors are executed one after the other based on the order defined. Then, the request reaches the controller. Once the controller does its job, the postHande() interceptor methods are executed before the response is sent back to the client. Again, if you have multiple interceptors, then the postHandle() is executed in the reverse order.
The exception thrown from the controller is handled in the @ControllerAdvice. Checkout this example code github.com/StackTipsLab/spring-boot-tutorials/blob/main/testing-movies-api/src/main/java/com/stacktips/movies/api/GlobalExceptionHandler.java
Hello Sir,
This is the first video of yours that I have watched, and I immediately subscribed to your channel because I was so impressed with the way you explain and the topics you cover.
Today, for the second time, an interviewer asked me about interceptors, and I didn't have a single line of response. However, after watching your video and practicing as you explained, I can now confidently discuss this topic and implement it in my projects as well.
I really want to thank you for explaining such an important topic on a free platform. The clarity of your explanation reflects your deep knowledge and experience.
Please continue to post content like this, which is rarely found on TH-cam. Once again, thank you so much, sir. 🙏
Thank you so much for your amazing feedback! I love to have you as part of this community. ~Nilan
Hands off, one the best videos about Spring interceptors. Good job!
Glad you liked it
Nice video.Please keep making such videos in more depth and from interview point of view.I faced this question in an interview. Thanks.
Best teacher are those who can teach any concept like butter and you did the same in this viedo
Thank you mate.
One of the best explanation found on TH-cam about interceptor😍
Thank you very much! Kind words as such push me to create more such informative contents!
One of the best explanations in TH-cam. 👍 Thank you
Thank you for your kind words 🙏. Happy learning.
Amazing content. Please add more content on spring and spring boot
Glad you like it shyam. More videos are coming.
Excellent Explanation of Spring boot Content .....please keep posting....🙏
Thank you @svronline1215, this is just the beginning. I have many plans to cover wide range of topics and lot more to come.
Very good explanation and demo. Expecting more videos from you on spring and springboot. It would help many budding developers like me if you put videos on explaining any real time project or build any small features of application in the similar way. Thank you so much for this video.
Thank you for kind words 🙏. I am working on spring boot basics tutorials series. Expect announcement soon.
OMG... really bestttt teacher.. your teaching is very concise words.. n each line you explained was fun
Thank you for your kind words!🙏💗
very nice explanation from beginner to experience. Thanks you
So nice of you
Thanks for this video ! Very detailed explaination and good presentation.
From beginners to advanced lvl tutorial
Noted. I will upload soon.
Tq sir
Excellent demonstration and explanation. continue to publish these fantastic videos on real-world Spring Boot use cases
Thanks you for kind words 🙏
Good explanation, very informative video, many people dont know about these topics, please keep posting these kind of topics which most of the other youtubers does not cover.
Thank you for your kind words 🙏. I am working on few other interesting topics, will share the details soon.
Thank you so much 👍🙏🏻 for this it's really awesome ❤🎉
Thanks for watching. 🤗
Cool explanation!!
Glad you liked it!
Great explanation. Thanks
Glad you liked it
Great 👏❤
Good explanation. Subscribed,
Excepting more videos like this on Spring Boot.
Thank you for the sub. 🙏
Nice explanation!!! Plz keep posting such invaluable content
Thank you 🙏👍
Excellent, very good video
Good to catch you bro, Waiting for more Content ☺
Very nice explanation and example. Thank you sir..
Thank you
absolutely amazing
thanks
Excellent explanation!!
Thank you 🙏
Excellent Explaination. Simple and straight to the point. Keep posting videos that could help the Java community. But I have doubt like whatever the examples that you have demonstrated can be achieved via servlet filters. Better if you would have explained with some example where using Interceptor gives an edge over the Servlet Api
Yes. Interceptors are convenient as they have spring context.
great...!!!
🙏 thanks
Great one
Really Good explanation!!!
Can we use filter as well to validate basic Auth as it can also intercept requests??
Sure we can do that as well. But if we need Spring Context, then use Interceptor.
explaination is so good.
Thank you 👍
Glad you liked.
Please make a detailed video on Spring Boot basics, like is it mandatory to have main method in an spring boot app to start the application, if not, then how will the SpringApplicaitonCOntext be initialised
looking forward for more spring content from you
Isn't the main method non mandatory if you are using war and mandatory if you are using an IDE for providing an executable Jar file?
As we are using Spring Boot with embedded Tomcat in this example, the main() method is required.
Read this on my blog: stacktips.com/articles/how-to-use-interceptor-in-spring-boot
Source code: github.com/StackTipsLab/spring-boot-tutorials/tree/main/spring-interceptor
Very nice demonstration. Can this strategy be used to log the incoming and outgoing json payload as well? Do you have any demonstration for logging the payloads.
For example, when a post end point is invoked by the client, I want to log the json payload (request) sent by the client and the json payload (response) sent back to the client.
Absolutely. interceptor can be used for logging request/response. But depending on the type of http client you use, you may not need to write any custom interceptor just for logging. Can I know which http client you intent to use?
@@TheTechMojo Thanks for reply.
The scenario I am dealing with is as follows:
There is a spring boot rest api application that has exposed "get" and "post" endpoints.
My requirement is to log the incoming request and outgoing response when these endpoints are called by any client.
The client may be Postman or even an another rest api may call these 2 endpoints.
The reason I am asking this question is because I have read that once interceptor has read the incoming request, the request is considered to have been consumed and hence controller will not receive any request at all and throw exception.
Alright. That's pretty simple. Check out this example. github.com/StackTipsLab/spring-boot-tutorials/blob/main/spring-interceptor/src/main/java/com/stacktips/interceptors/LogHandlerInterceptor.java
Good explanation. I have a question here - is there a way to modify the request in the interceptor before it reaches the controller?
Yes that is possible using interceptor. You could also achieve that using servlet filters.
Sir plz make a complete tutorial about spring boot with authentication project.
Thank you. I am already working on Spring boot for beginners series. Due to holiday I am delayed by few days. But expect the first one soon.
Good job continue...
Please post video on adding requestId in a log using MDC and interceptor for each thread
After preHander interceptor, I want to call security interceptor
Then postHander interceptor method
Is it possible, if yes how?
The preHande() method is called before the request reaches the controller. If you have multiple interceptors, you can order them using the @Order annotation. All interceptors are executed one after the other based on the order defined.
Then, the request reaches the controller.
Once the controller does its job, the postHande() interceptor methods are executed before the response is sent back to the client. Again, if you have multiple interceptors, then the postHandle() is executed in the reverse order.
I have one doubt, for unauthorized how did you send that json response ?
The exception thrown from the controller is handled in the @ControllerAdvice. Checkout this example code github.com/StackTipsLab/spring-boot-tutorials/blob/main/testing-movies-api/src/main/java/com/stacktips/movies/api/GlobalExceptionHandler.java
How to use jwt along with interceptor
Clean🤌
Amazing content. Please add more content on spring and spring boot
Thank you @@harshwardhanparmar8258. This is just the beginning, I have many more Spring Boot tutorial videos lined up for the weeks to come.