resthub / springmvc-router

Adds route mapping capacity to any "Spring MVC based" webapp. Uses playframework.org Router implementation.

Home Page:http://resthub.github.com/springmvc-router/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Autodetection of HandlerInterceptors doesn't work

sazzer opened this issue · comments

In standard Spring MVC, using Java Config, you can define interceptors by overriding the addInterceptors method of the WebMvcConfigurerAdapter base class. Doing so doesn't work for the interceptors to be picked up and used by the router. Instead they have to be configured directly onto the RouterHandlerMapping object

Do you have a pointer/example for this use case?
I'm trying to implement a test case for this.

Quite simple really - You write a class with the @configuration annotation on it, and extending the WebMvcConfigurerAdapter class. You then override the addInterceptors method of this class, and you have some @bean methods in it to define controllers. You can then boot up a Spring configuration using this class as your configuration instead of/as well as an XML file, and you should get the interceptors that were created in the addInterceptors added automatically to the handlers...

I found that the default configuration WebMvcConfigurationSupport configures handlermappings instances and their order.

In our case, WebMvcConfigurerAdapter only relies on this default configuration and thus doesn't apply interceptors to the right handlermapping, because the RouterHandlerMapping isn't itself declared in a JavaConfig class and doesn't "set" interceptors on itself.

Could an abstract class like WebMvcConfigurationSupport be useful to you if it creates and registers the RouterHandlerMapping class? This class would look a lot like WebMvcConfigurationSupport and should be in the same package because of protected methods within spring.

will be fixed by issue #28

Done.