resthub / springmvc-router

Adds route mapping capacity to any "Spring MVC based" webapp. Uses playframework.org Router implementation.
http://resthub.github.com/springmvc-router/
Other
167 stars 63 forks source link

Autodetection of HandlerInterceptors doesn't work #23

Closed sazzer closed 11 years ago

sazzer commented 11 years ago

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

bclozel commented 11 years ago

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

sazzer commented 11 years ago

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...

bclozel commented 11 years ago

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.

bclozel commented 11 years ago

will be fixed by issue #28

bclozel commented 11 years ago

Done.