2011-09-13 61 views
4

我正在使用WebContentInterceptor来启用长期存在的静态资源缓存。尽管我们有他们在3种不同的路径,CSS,JS和图像。Spring MVC为多个路径共享相同的拦截器

有没有一种方法可以在多个映射之间共享拦截器bean,而不必将它们全部置于共享路径之下?

回答

6

我需要更多的信息来确认设置是我的设想;但是,你有没有尝试过...

<mvc:annotation-driven /> 

    <mvc:interceptors> 
      <mvc:interceptor> 
       <mvc:mapping path="/site/*" /> 
       <mvc:mapping path="/add/*" />\ 
          <mvc:mapping path="/edit" /> 
       <bean 
     class="com.test.MyInterceptor" /> 
      </mvc:interceptor> 
     </mvc:interceptors> 
0

以上回答不起作用。而我找不到任何东西,如paths但找到了一种解决方法。

<mvc:interceptors> 
     <mvc:interceptor> 
      <mvc:mapping path="/notes/**" />    
      <bean class="com.bridgelabz.todoApp.interceptor.LoginInterceptor" /> 
     </mvc:interceptor> 

     <mvc:interceptor> 
      <mvc:mapping path="/user/getUserById" />    
      <bean class="com.bridgelabz.todoApp.interceptor.LoginInterceptor" /> 
     </mvc:interceptor>