解決Spring MVC整合Shiro出現無法訪問靜態資源文件的問題

問題描述:Chrome 控制檯下報“Resource interpreted as Stylesheet but transferred with MIME type text/html”,css,js等文件無法正確被加載。

原因出在了配置shiro過濾器時設置了“/**=user”,使得在未登錄狀態下無法正確加載靜態文件。

解決方案:shiro過濾器配置攔截器鏈中添加”/static/**=anno”即可,”/static/**”爲靜態資源文件路徑。

<!-- Shiro的Web過濾器 -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
        <property name="loginUrl" value="/user/login"/>
        <property name="filters">
            <util:map>
                <entry key="authc" value-ref="formAuthenticationFilter"/>
            </util:map>
        </property>
        <property name="filterChainDefinitions">
            <value>
                /=authc
                /index=authc
                /user/login=authc
                /logout=logout
                /static/**=anon<!--設置靜態資源文件爲遊客可訪問-->
                /**=user
            </value>
        </property>
    </bean>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章