SpringMVC配置错误页后, Shiro报错No SecurityManager accessible to the calling code...

Root Cause:

org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.  This is an invalid application configuration.

网上搜罗来的解释说是web.xml少了这一段, 但是我有:


    <filter>
        <filter-name>shiroFilterfilter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxyfilter-class>
    filter>
    <filter-mapping>
        <filter-name>shiroFilterfilter-name>
        <url-pattern>/*url-pattern>
    filter-mapping>

后来发现是还少了几行, 完整体应该是:


    <filter>
        <filter-name>shiroFilterfilter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxyfilter-class>
    filter>
    <filter-mapping>
        <filter-name>shiroFilterfilter-name>
        <url-pattern>/*url-pattern>
        <dispatcher>REQUESTdispatcher>
        <dispatcher>FORWARDdispatcher>
        <dispatcher>INCLUDEdispatcher>
        <dispatcher>ERRORdispatcher>
    filter-mapping>

表示这4种都要经过shiro拦截器。我之前配置的404页面里回去访问shiro的SecurityUtils.getSubject(),若error不被拦截, 则这个请求是无法获取Subject的, 因此报错

你可能感兴趣的:(shiro)