使用mvc:annotation-driven的時候,使用不了DefaultAnnotationHandlerMapping的問題,解決辦法

問題描述
當使用<mvc:annotation-driven/> 的時候,我們使用不了過濾器:代碼如下;

<!-- 配置過濾器 -->
    <bean
        class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="interceptors">
            <list>
                <bean class="com.founder.filter.ParamInitInterceptor" />
            </list>
        </property>
    </bean>

分析原因http://blog.csdn.net/z3881006/article/details/78253684

解決辦法
可以把

<!-- 啓動SpringMVC註解 -->
<mvc:annotation-driven/>

替換成

<!-- 啓動SpringMVC註解功能,完成請求和註解POJO映射 -->
    <bean
        class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <!-- 輸出純文本 -->
                <bean
                    class="org.springframework.http.converter.StringHttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                        </list>
                    </property>

                </bean>
                <!-- 輸出JSON -->
                <!-- 避免IE在ajax請求時,返回json出現下載 -->
                <bean id="jacksonMessageConverter"
                    class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                    <property name="supportedMediaTypes">
                        <list>
                            <value>text/html;charset=UTF-8</value>
                        </list>
                    </property>
                </bean>

            </list>

        </property>

    </bean>
發佈了86 篇原創文章 · 獲贊 94 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章