<mvc:annotation-driven>和DefaultAnnotationHandlerMapping

There are two ways to configure interceptors in spring:

 

<mvc:annotation-driven />
 
<!-- *************openSessionInViewInterceptor  *************-->
   <bean id="openSessionInViewInterceptor"class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>
 
   <!--
      **************interceptors **************************
   -->
   <beanclass="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
      <property name="interceptors">
        <list>
           <ref bean="openSessionInViewInterceptor" />
        </list>
      </property>
   </bean>
 
   <mvc:interceptors>
      <mvc:interceptor>
        <mvc:mapping path="/**/*.htm" />
        <bean id="metaInfoInterceptor" class="com.jumbo.web.interceptor.MetaInfoInterceptor"/>
      </mvc:interceptor>
   </mvc:interceptors>

 

If the above two ways are combined and configured, problems may occur .

The reason is: DefaultAnnotationHandlerMapping is started twice , and the controller  is Mapped twice. 

mvc:annotation-driven will automatically register two instances of DefaultAnnotationHandlerMapping andAnnotationMethodHandlerAdapter

The DefaultAnnotationHandlerMapping started at this time  , openSessionInViewInterceptor did not work , it only worked when I configured the DefaultAnnotationHandlerMapping again 

The code of the controller  just uses the DefaultAnnotationHandlerMapping that was started for the first time,  resulting in no openSessionInViewInterceptor and no session exception . 

 

Transfer: http://feitianbenyue.iteye.com/blog/1271181

<!--EndFragment--><!--EndFragment-->

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939950&siteId=291194637