解决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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章