Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring 3 <mvc:interceptors> flawed?
    primarykey
    data
    text
    <p>I have a Spring 2.5.x application which I'm migrating to Spring 3 and just bumped into a little problem.</p> <p>I have an handler mapping like so:</p> <pre><code>&lt;bean id="handlerMappings1" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt; &lt;property name="interceptors"&gt; &lt;list&gt; &lt;ref bean="interceptor1" /&gt; &lt;ref bean="interceptor2" /&gt; .... &lt;ref bean="interceptorN" /&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="urlMap"&gt; &lt;map&gt; &lt;entry key="/url1.html" value-ref="controller1" /&gt; &lt;entry key="/url2.html" value-ref="controller2" /&gt; .... &lt;entry key="/url100.html" value-ref="controller100" /&gt; &lt;/map&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>and another one like this:</p> <pre><code> &lt;bean id="handlerMappings2" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt; &lt;property name="urlMap"&gt; &lt;map&gt; &lt;entry key="/urlA.html" value-ref="controllerA" /&gt; &lt;entry key="/urlB.html" value-ref="controllerB" /&gt; .... &lt;entry key="/urlN.html" value-ref="controllerN" /&gt; &lt;/map&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>I'm slowly replacing both with <code>@RequestMapping</code> annotations with a <code>&lt;context:component-scan&gt;</code> (which basically registers a <a href="http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/web/servlet/mvc/annotation/DefaultAnnotationHandlerMapping.html" rel="nofollow"><code>DefaultAnnotationHandlerMapping</code></a>).</p> <p>In Spring 3 I saw the <a href="http://blog.springsource.com/2009/12/21/mvc-simplifications-in-spring-3-0/" rel="nofollow"><code>&lt;mvc:interceptors&gt;</code></a> tag which can be used to add interceptors to certain URLs but you can specify only one interceptor, at least that's what I see <a href="http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" rel="nofollow">from the schema</a>.</p> <p>From what I can figure, I have to register one of these for each interceptor which will duplicate all my URLs for as many times as I have interceptors (and I don't even know in what order they will run). </p> <p>On the other hand I can't add the iterceptors on the <code>DefaultAnnotationHandlerMapping</code> because they will run for all my controllers annotated with <code>@RequestMapping</code> and I don't want that.</p> <p>So how can I specify interceptors is Spring 3 for some URLs, without repeating the URL's and keeping the URL to controller mapping based on the <code>@RequestMapping</code> annotation?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload