SpringMVC整合Shiro和Swagger產生的路徑過濾問題

SSM整合Swagger和Shiro時出現的問題:

一:啓動swagger報錯Unable to infer base url. This is common when using dynamic servlet
SpringMVC整合Shiro和Swagger產生的路徑過濾問題
解決方法html

  • 在shiro配置文件的自定義的過濾鏈中加上一下代碼:
    <!-- swagger有關的不攔截 -->
                /swagger-ui.html = anon
                /webjars/** = anon
                /v2/** = anon
                /swagger-resources/** = anon
                <!-- shiro提供了退出登陸的配置`logout`, 會生成路徑爲`logout`的請求,訪問這個地址即會退出當前帳戶並清空緩存 -->
                /backend/admin/logout = logout
  • swagger的配置類只可以在SpringMVC的配置文件中被掃描,不能交給spring容器處理。springMVC只是spring的一個子容器,存在父子關係。若是swagger讓spring的context加載,那麼swagger的那些url用springmvc的攔截器是攔截不到的
     
    springMVC的配置文件
    <!-- SpringMVC的配置文件,包含網站跳轉邏輯的控制,配置 -->
    <context:component-scan base-package="com.zgz.traintickets.controller,swagger" use-default-filters="false">
        <!-- 只掃描控制器 -->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

     
    spring的配置文件之一:
    SpringMVC整合Shiro和Swagger產生的路徑過濾問題
     web

  • 注意事項
    記得清理瀏覽器和服務器的緩存
相關文章
相關標籤/搜索