How it works...

When it comes to configuring the Spring MVC internals, it is not as simple as just defining a bunch of beans at least not always. This is due to the need to provide a more fine-tuned mapping of the MVC components to requests. To make things easier, Spring provides us with a collection of default methods in WebMvcConfigurer interface that we can extend and override the settings of that we need.

In the particular case of configuring interceptors, we are overriding the addInterceptors(InterceptorRegistry registry) method. This is a typical callback method where we are given a registry in order to register as many additional interceptors as we need. During the MVC autoconfiguration phase, Spring Boot, just like in the case of filters, detects instances of WebMvcConfigurer and sequentially calls the callback methods on all of them. It means that we can have more than one implementation of the WebMvcConfigurer class if we want to have some logical separation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.38.3