微服務使用Shiro 框架時 SecurityUtils.getSubject() 時報錯 :org.apache.shiro.UnavailableSecurityManagerException

異常信息:

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.

原因:

我自身的原因,是因爲在微服務中,把shiro配置文件只是放在了用戶服務中,別的服務沒有,而我又配置了redis 服務器用於 shiro的 SessionId 共享(由於從redis中取sessionId需要對配置文件進行redis 與shiro的整合配置)所以當我訪問到沒有shiro配置文件的服務時,則會報出該異常。

解決方案:

將shiro的配置文件放入當前訪問的服務中即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章