spring mvc <mvc:annotation-driven/> 自訂攔截器不走,springmvc攔截器

來源:互聯網
上載者:User

spring mvc <mvc:annotation-driven/> 自訂攔截器不走,springmvc攔截器

<mvc:annotation-driven/> 這個便簽會註冊2個自訂攔截器,所以導致請求過來就會自己去走註冊的這2個攔截器和定義的一堆bean

但是這個便簽是必須得定義的

直接貼代碼吧

<beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:context="http://www.springframework.org/schema/context"       xmlns:mvc="http://www.springframework.org/schema/mvc"       xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://www.springframework.org/schema/context        http://www.springframework.org/schema/context/spring-context.xsd        http://www.springframework.org/schema/mvc        http://www.springframework.org/schema/mvc/spring-mvc.xsd        ">            <mvc:default-servlet-handler/>    <mvc:annotation-driven/>        <context:component-scan base-package="com.muke.controller"  use-default-filters="false">        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>    </context:component-scan>         <!-- 對轉向頁面的路徑解析。prefix:首碼, suffix:尾碼 -->   <!--JSP視圖解析器-->    <bean id="viewResolverJsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver">        <property name="prefix" value="/"/>        <property name="suffix" value=".jsp"/>    </bean>    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">        <property name="templateLoaderPath" value="/WEB-INF/freemarker"/>    </bean>    <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">        <!-- 解決freemarker中文亂碼 -->        <property name="contentType" value="text/html;charset=UTF-8"/>                <property name="cache" value="true"/>        <property name="prefix" value=""/>        <property name="suffix" value=".ftl"/>        <property name="order" value="0"/>    </bean>        <!-- 攔截器 -->    <mvc:interceptors>        <mvc:interceptor >            <mvc:mapping path="/**"/>            <!--對於靜態資源,可以通過尾碼名-->            <!--<mvc:exclude-mapping path="/**/*.js"/>            <mvc:exclude-mapping path="/**/*.css"/>            <mvc:exclude-mapping path="/**/*.jpg"/>            <mvc:exclude-mapping path="/**/*.gif"/>            <mvc:exclude-mapping path="/**/*.png"/>-->            <!--也可以通過檔案夾, 加這些exclude-mapping就不會被攔截器攔截到,資源能夠正常訪問-->            <mvc:exclude-mapping path="/html/**"/>            <mvc:exclude-mapping path="/back_css/**"/>            <mvc:exclude-mapping path="/back_js/**"/>            <mvc:exclude-mapping path="/back_img/**"/>            <mvc:exclude-mapping path="/back_other/**"/>            <mvc:exclude-mapping path="/layer/**"/>            <mvc:exclude-mapping path="/laypage/**"/>            <bean class="com.muke.springMVC.interceptors.DefaultInterceptors"/>                    </mvc:interceptor>           <mvc:interceptor>               <mvc:mapping path="/manage/menuBar/**"/>               <bean class="com.muke.springMVC.interceptors.ManagerPowerInterceptors"></bean>           </mvc:interceptor>             </mvc:interceptors></beans>

通過自訂攔截器來過濾掉靜態資源

這個問題困擾了我2天,整整熬了2天,翻遍了部落格員和百度,各種瞎扯淡,也反思了自己找問題的方式,最後一天自己嘗試著去尋找問題的根源,但還是解決不了

最後只能求救我師傅解決了。只能說自己功力不夠和思考問題的方向錯了吧

還要有這個設定檔

<?xml version="1.0" encoding="UTF-8"?><beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:context="http://www.springframework.org/schema/context"       xmlns="http://www.springframework.org/schema/beans"       xsi:schemaLocation="        http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd        http://www.springframework.org/schema/context        http://www.springframework.org/schema/context/spring-context-4.1.xsd">    <context:component-scan base-package="com.muke" use-default-filters="false">        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>    </context:component-scan></beans>

spring 和spring MVC都會掃描@Controller這個註解,這樣就只掃描一次了

已經忘記這個坑我走了多久了。從配置靜態目錄,少了這個這個標籤導致@Controller這個註解沒生效,到現在,唉真坑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.