异常处理-No SecurityManager accessible to the calling code

十二月 02, 2016 3:38:35 下午 org.apache.catalina.core.ApplicationDispatcher invoke

严重: Servlet.service() for servlet springServlet threw exception

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.

      at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)

      at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:627)

      at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)

      at com.hylandtec.ibank.common.UserSessionInterceptor.preHandle(UserSessionInterceptor.java:30)

      at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:130)

      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919)

      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)

      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)

      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)

      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)

      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:488)

      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)

      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)

      at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:466)

      at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:337)

      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:202)

      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)

      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)

      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)

      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)

      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)

      at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)

      at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)

      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

      at java.lang.Thread.run(Thread.java:745)

十二月 02, 2016 3:38:35 下午 org.apache.catalina.core.StandardHostValve custom

严重: Exception Processing ErrorPage[errorCode=404, location=/error/404.html]

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is 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.

      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)

      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)

      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)

      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:488)

      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)

      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)

      at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:466)

      at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:337)

      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:202)

      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)

      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)

      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)

      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)

      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)

      at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)

      at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)

      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

      at java.lang.Thread.run(Thread.java:745)

Caused by: 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.

      at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)

      at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:627)

      at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)

      at com.hylandtec.ibank.common.UserSessionInterceptor.preHandle(UserSessionInterceptor.java:30)

      at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:130)

      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919)

      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)

      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)

      ... 24 more

出现问题原因有:

1,没有配置 

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">

            <!-- realm认证和授权,从数据库读取资源 -->

            <property name="realm" ref="shiroDbRealm" />

            <!-- cacheManager,集合spring缓存工厂 -->

            <property name="cacheManager" ref="shiroMemCachedManager" />

</bean>

2,web.xml  斜体部分不能少

 

<filter>

    <filter-name>shiroFilter</filter-name>

    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>

    <init-param>

      <param-name>targetFilterLifecycle</param-name>

      <param-value>true</param-value>

    </init-param>

  </filter>

  <filter-mapping>

    <filter-name>shiroFilter</filter-name>

    <url-pattern>/*</url-pattern>

    <dispatcher>REQUEST</dispatcher>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>ERROR</dispatcher>

    <dispatcher>INCLUDE</dispatcher>

  </filter-mapping>

 

3,关于shiro放置的web.xml的顺序

web.xml中有其它filter 引用到 shiroFilter 里的属性或者其它。

这些filter 要放在 shiroFilter的后面。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值