报错信息
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 ) ~ [ shiro- core- 1.9 .0 . jar: 1.9 .0 ] at org. apache. shiro. subject. Subject $Builder . < init> ( Subject . java: 626 ) ~ [ shiro- core- 1.9 .0 . jar: 1.9 .0 ] at org. apache. shiro. SecurityUtils. getSubject ( SecurityUtils . java: 56 ) ~ [ shiro- core- 1.9 .0 . jar: 1.9 .0 ] at com. lotus. shiro. controller. FirstController. controll ( FirstController . java: 26 ) ~ [ classes/ : na] at sun. reflect. NativeMethodAccessorImpl. invoke0 ( Native Method ) ~ [ na: 1.8 .0_131 ] at sun. reflect. NativeMethodAccessorImpl. invoke ( NativeMethodAccessorImpl . java: 62 ) ~ [ na: 1.8 .0_131 ] at sun. reflect. DelegatingMethodAccessorImpl. invoke ( DelegatingMethodAccessorImpl . java: 43 ) ~ [ na: 1.8 .0_131 ] at java. lang. reflect. Method. invoke ( Method . java: 498 ) ~ [ na: 1.8 .0_131 ] at org. springframework. web. method. support. InvocableHandlerMethod. doInvoke ( InvocableHandlerMethod . java: 205 ) ~ [ spring- web- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. method. support. InvocableHandlerMethod. invokeForRequest ( InvocableHandlerMethod . java: 150 ) ~ [ spring- web- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. servlet. mvc. method. annotation. ServletInvocableHandlerMethod. invokeAndHandle ( ServletInvocableHandlerMethod . java: 117 ) ~ [ spring- webmvc- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. servlet. mvc. method. annotation. RequestMappingHandlerAdapter. invokeHandlerMethod ( RequestMappingHandlerAdapter . java: 895 ) ~ [ spring- webmvc- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. servlet. mvc. method. annotation. RequestMappingHandlerAdapter. handleInternal ( RequestMappingHandlerAdapter . java: 808 ) ~ [ spring- webmvc- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. servlet. mvc. method. AbstractHandlerMethodAdapter. handle ( AbstractHandlerMethodAdapter . java: 87 ) ~ [ spring- webmvc- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. servlet. DispatcherServlet. doDispatch ( DispatcherServlet . java: 1072 ) ~ [ spring- webmvc- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. servlet. DispatcherServlet. doService ( DispatcherServlet . java: 965 ) ~ [ spring- webmvc- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. servlet. FrameworkServlet. processRequest ( FrameworkServlet . java: 1006 ) ~ [ spring- webmvc- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. servlet. FrameworkServlet. doGet ( FrameworkServlet . java: 898 ) ~ [ spring- webmvc- 5.3 .31 . jar: 5.3 .31 ] at javax. servlet. http. HttpServlet. service ( HttpServlet . java: 529 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 4.0 . FR ] at org. springframework. web. servlet. FrameworkServlet. service ( FrameworkServlet . java: 883 ) ~ [ spring- webmvc- 5.3 .31 . jar: 5.3 .31 ] at javax. servlet. http. HttpServlet. service ( HttpServlet . java: 623 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 4.0 . FR ] at org. apache. catalina. core. ApplicationFilterChain. internalDoFilter ( ApplicationFilterChain . java: 209 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. ApplicationFilterChain. doFilter ( ApplicationFilterChain . java: 153 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. tomcat. websocket. server. WsFilter. doFilter ( WsFilter . java: 51 ) ~ [ tomcat- embed- websocket- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. ApplicationFilterChain. internalDoFilter ( ApplicationFilterChain . java: 178 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. ApplicationFilterChain. doFilter ( ApplicationFilterChain . java: 153 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. springframework. web. filter. RequestContextFilter. doFilterInternal ( RequestContextFilter . java: 100 ) ~ [ spring- web- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. filter. OncePerRequestFilter. doFilter ( OncePerRequestFilter . java: 117 ) ~ [ spring- web- 5.3 .31 . jar: 5.3 .31 ] at org. apache. catalina. core. ApplicationFilterChain. internalDoFilter ( ApplicationFilterChain . java: 178 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. ApplicationFilterChain. doFilter ( ApplicationFilterChain . java: 153 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. springframework. web. filter. FormContentFilter. doFilterInternal ( FormContentFilter . java: 93 ) ~ [ spring- web- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. filter. OncePerRequestFilter. doFilter ( OncePerRequestFilter . java: 117 ) ~ [ spring- web- 5.3 .31 . jar: 5.3 .31 ] at org. apache. catalina. core. ApplicationFilterChain. internalDoFilter ( ApplicationFilterChain . java: 178 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. ApplicationFilterChain. doFilter ( ApplicationFilterChain . java: 153 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. springframework. web. filter. CharacterEncodingFilter. doFilterInternal ( CharacterEncodingFilter . java: 201 ) ~ [ spring- web- 5.3 .31 . jar: 5.3 .31 ] at org. springframework. web. filter. OncePerRequestFilter. doFilter ( OncePerRequestFilter . java: 117 ) ~ [ spring- web- 5.3 .31 . jar: 5.3 .31 ] at org. apache. catalina. core. ApplicationFilterChain. internalDoFilter ( ApplicationFilterChain . java: 178 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. ApplicationFilterChain. doFilter ( ApplicationFilterChain . java: 153 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. StandardWrapperValve. invoke ( StandardWrapperValve . java: 168 ) ~ [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. StandardContextValve. invoke ( StandardContextValve . java: 90 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. authenticator. AuthenticatorBase. invoke ( AuthenticatorBase . java: 481 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. StandardHostValve. invoke ( StandardHostValve . java: 130 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. valves. ErrorReportValve. invoke ( ErrorReportValve . java: 93 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. core. StandardEngineValve. invoke ( StandardEngineValve . java: 74 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. catalina. connector. CoyoteAdapter. service ( CoyoteAdapter . java: 342 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. coyote. http11. Http11Processor. service ( Http11Processor . java: 390 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. coyote. AbstractProcessorLight. process ( AbstractProcessorLight . java: 63 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. coyote. AbstractProtocol $ConnectionHandler . process ( AbstractProtocol . java: 928 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. tomcat. util. net. NioEndpoint $SocketProcessor . doRun ( NioEndpoint . java: 1794 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. tomcat. util. net. SocketProcessorBase. run ( SocketProcessorBase . java: 52 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. tomcat. util. threads. ThreadPoolExecutor. runWorker ( ThreadPoolExecutor . java: 1191 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. tomcat. util. threads. ThreadPoolExecutor $Worker . run ( ThreadPoolExecutor . java: 659 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at org. apache. tomcat. util. threads. TaskThread $WrappingRunnable . run ( TaskThread . java: 61 ) [ tomcat- embed- core- 9.0 .83 . jar: 9.0 .83 ] at java. lang. Thread. run ( Thread . java: 748 ) [ na: 1.8 .0_131 ]
解决方法
@Bean public DefaultWebSecurityManager defaultWebSecurityManager ( ) { DefaultWebSecurityManager defaultWebSecurityManager = new DefaultWebSecurityManager ( ) ; HashedCredentialsMatcher matcher = new HashedCredentialsMatcher ( ) ; matcher. setHashAlgorithmName ( "MD5" ) ; matcher. setHashIterations ( 3 ) ; authRealm. setCredentialsMatcher ( matcher) ; defaultWebSecurityManager. setRealm ( authRealm) ; SecurityUtils . setSecurityManager ( defaultWebSecurityManager) ; return defaultWebSecurityManager; }