赞
踩
今天在调试代码的时候,报了这么一个错,排查半天,终于找到解决方法,具体报错如下图
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
- 16:29:03.059 [http-nio-80-exec-25] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - [log,175] - Servlet.service() for servlet [dispatcherServlet] 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:626)
- at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
- at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSubject(ShiroHttpServletRequest.java:89)
- at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSession(ShiroHttpServletRequest.java:154)
- at org.springframework.web.util.WebUtils.getSessionId(WebUtils.java:359)
- at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1145)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1023)
- at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
- at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:102)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:102)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
- at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:711)
- at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:632)
- at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:600)
- at org.apache.catalina.core.AsyncContextImpl$AsyncRunnable.run(AsyncContextImpl.java:587)
- at org.apache.catalina.core.AsyncContextImpl.doInternalDispatch(AsyncContextImpl.java:353)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:194)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
- at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
- at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:250)
- at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:241)
- at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:59)
- at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
- at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
- at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
- at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
- at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
- at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
- at java.lang.Thread.run(Thread.java:748)
- 16:29:03.060 [http-nio-80-exec-25] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - [log,175] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [java.lang.RuntimeException: Error during asynchronous dispatch] with 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.
- at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
- at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:626)
- at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
- at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSubject(ShiroHttpServletRequest.java:89)
- at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSession(ShiroHttpServletRequest.java:154)
- at org.springframework.web.util.WebUtils.getSessionId(WebUtils.java:359)
- at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1145)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1023)
- at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
- at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:102)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:102)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
- at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:711)
- at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:632)
- at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:600)
- at org.apache.catalina.core.AsyncContextImpl$AsyncRunnable.run(AsyncContextImpl.java:587)
- at org.apache.catalina.core.AsyncContextImpl.doInternalDispatch(AsyncContextImpl.java:353)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:194)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
- at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
- at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:250)
- at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:241)
- at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:59)
- at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
- at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
- at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
- at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
- at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
- at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
- at java.lang.Thread.run(Thread.java:748)
是因为Apache Shiro无法找到SecurityManager。在Apache Shiro中,SecurityManager是中心安全控制器,所有安全相关的操作都会与它交互。这个错误可能的原因是没有正确地设置或者初始化Shiro的SecurityManager。
在调用接口处添加以下代码(初始化一下)
- DefaultSecurityManager securityManager = new DefaultSecurityManager();
- SecurityUtils.setSecurityManager(securityManager);
问题要是解决了,记得点个赞
如果小伙伴们有什么疑问,欢迎下面评论。欢迎指正。如还有什么不懂的加我 QQ:517861659
如果没有及时回复,可以点我先问问AI机器人https://chatgpt.byabstudio.com/login?code=202307011314
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。