2011-11-16 76 views
4

我在Spring 3.0.6中使用@Configuration来使用依赖注入而不使用.xml定义文件。在@Configuration环境中配置HandlerInterceptors

我使用的是混合的方法来定义控制器,我把它们放在DispatcherServlet@Configuration,使用@Bean("/sample/path")使用@RequestMapping在他们的方法以进一步缩小的映射(包括使用它来追加到bean的路径)。

这对默认的HandlerMapper配置非常有效。

现在,我想添加一些HandlerInterceptors混合。看来我需要复制默认的HandlerMapper配置,然后添加我的HandlerInterceptor

但是,这似乎不是一个好主意。有没有办法将我的HandlerInterceptor添加到默认的HandlerMapper配置中?

回答

1

“default HandlerMapper confgiuration”的意思是声明一个BeanNameUrlHandlerMapping和一个DefaultAnnotationHandlerMapping bean,然后设置它们的“拦截器”属性?在这种情况下,我看不到很多重复。

另一种方法是声明一个MappedInterceptor类型的bean。它按类型检测并应用于所有传入请求或受路径模式限制。

+0

酷! MappedInterceptor未在参考手册中提及! – alex