Java – configure handlerinterceptors in the @ configuration context
I'm in spring 3.0 In 6, @ configuration is used to use dependency injection instead of XML definition file
I use mixed methods to define controllers. I put them in @ configuration of dispatcherservlet, use @ bean ("/ sample / path") and use @ requestmapping in their methods to further refine the mapping (including the path it attaches to the bean)
This is very effective for the default handler mapper configuration
Now, I want to add some handlerinterceptors It seems that I need to copy the default handlermapper configuration and add my handlerinterceptor
However, this does not seem to be a good idea Is there any way to add my handlerinterceptor to the default handlermapper configuration?
Solution
By "default handlermapper configuration", do you mean to declare a beannameurlhandlermapping and a defaultannotationhandlermapping bean, and then set their "interceptor" property? In this case, I don't see much repetition
Another way is to declare a bean of type mappedinterceptor It detects and applies to all incoming requests by type or is limited by path mode