Announcement Announcement Module
Collapse
No announcement yet.
MVC: Interceptors and static content Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MVC: Interceptors and static content

    I am using 3.1.0.

    I have excluded static content as follows in the spring xml file:

    <mvc:resources mapping="/js/**" location="/js/" />
    <mvc:resources mapping="/images/**" location="/images/" />
    <mvc:resources mapping="/css/**" location="/css/" />

    And interceptor is defined as follows

    <mvc:interceptors>
    <bean class="AuthenticationInterceptor" />
    </mvc:interceptors>

    it seems interceptor is still getting called for js, css and images files. It seems resource mapping for static content is not honored by interceptor.

    Am I missing something here?

    Bharat

  • #2
    You haven't excluded anything... You added an interceptor which wraps each request...

    Please use [ code][/code ] tags when posting code.

    Comment


    • #3
      Thanks Marten.

      I was under an impression when we define the resource location as follows, they are excluded from servlet-mapping which includes both controllers and interceptors.
      Code:
      <mvc:resources mapping="/js/**" location="/js/" />
      I could make it work by passing interceptor reference to the handler mapping. Working configuration looks as follows:

      Code:
      	
              <mvc:resources mapping="/js/**" location="/js/" />
      	<mvc:resources mapping="/images/**" location="/images/" />
      	<mvc:resources mapping="/css/**" location="/css/" />
      
      	<bean id="authInterceptor" class="AuthenticationInterceptor"/>
      	
              <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      		<property name="interceptors">
      			<list>
      				<ref bean="authInterceptor" />
      			</list>
      		</property>
      		<property name="mappings">
      			<value>
      				/=loginController
      				/action/**/=actionController
      			</value>
      		</property>
      	</bean>
      Is there a way we can define exclusion criteria when we use
      Code:
      <mvc:interceptors>
      ?

      Regards,
      Bharat

      Comment


      • #4
        I suggest a read of the reference guide... How to specify url mappings for interceptors is explained in there.

        When using mvc:interceptors by default they are registered for all HandlerMappings.

        Comment


        • #5
          Indeed interceptors mapped through the MVC namespace are declared as beans and detected by all HandlerMapping types without exception. I'm afraid that can't be changed at this point.

          The MVC Java config however does this differently. Instead of declaring MappedInterceptor beans, it sets interceptors on the HandlerMapping types it creates and the one that serves resources is excluded. Take a look at MVC Java config. The section on configuring Spring MVC in 3.1 should be up-to-date.

          Comment

          Working...
          X