1. 程式人生 > >Spring整合Shiro出現There is no session with id [XXX] with root cause問題的解決方案

Spring整合Shiro出現There is no session with id [XXX] with root cause問題的解決方案

最近使用spring + shiro整合的時候出現一個非常頭疼的問題,就是會經常出現There is no session with id [XXX]的問題,而且非常難調試出問題的所在,原始碼也看了關於shiro的部分,但是原因還是找不到。廢話不多說,直接上配置檔案shiro.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:cache="http://www.springframework.org/schema/cache"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:websocket="http://www.springframework.org/schema/websocket"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.2.xsd
	http://www.springframework.org/schema/cache
	http://www.springframework.org/schema/cache/spring-cache-4.2.xsd
	http://www.springframework.org/schema/task
	http://www.springframework.org/schema/task/spring-task-4.2.xsd">

	<bean id="shiroSessionListener" class="com.vkl.mtjg.setting.shiro.ShiroSessionListener"></bean>
 	<!-- 會話DAO,sessionManager裡面的session需要儲存在會話Dao裡,沒有會話Dao,session是瞬時的,沒法從  
     sessionManager裡面拿到session --> 
	<bean id="sessionDAO" class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO">
		<property name="activeSessionsCacheName" value="shiro-activeSessionCache"/>
	</bean>
<!-- 會話管理器 --> <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager"> <!-- Shiro去掉URL中的JSESSIONID --> <property name="sessionIdUrlRewritingEnabled" value="false" /> <property name="globalSessionTimeout" value="1800000"/> <property name="sessionDAO" ref="sessionDAO"></property>
<property name="deleteInvalidSessions" value="true"/> <property name="sessionIdCookieEnabled" value="true"/> <property name="sessionIdCookie" ref="sessionIdCookie"/> <!-- 定時驗證session時間間隔(毫秒) --> <property name="sessionValidationInterval" value="300000" /> <!-- 定時驗證session有效性 --> <property name="sessionValidationSchedulerEnabled" value="true"/> <property name="cacheManager" ref="shiroEhcacheManager"/> </bean> <!-- 配置shiro 快取的一個管理器 --> <bean id="shiroEhcacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"> <property name="cacheManagerConfigFile" value="classpath:ehcache.xml" /> </bean> <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie"> <constructor-arg name="name" value="SHRIOSESSIONID"/> <property name="maxAge" value="-1"/> </bean> <!-- 踢人會話過濾器 --> <bean id="kickoutSessionFilter" class="com.vkl.mtjg.setting.shiro.KickoutSessionFilter"> <property name="sessionManager" ref="sessionManager"/> <property name="cacheManager" ref="shiroEhcacheManager"/> <property name="kickoutAfter" value="false"/> <property name="maxSession" value="1"/> <property name="kickoutUrl" value="/index.do"/> </bean> <bean id="ShiroSessionFilter" class="com.vkl.mtjg.setting.shiro.ShiroSessionFilter"> </bean> <!-- 配置shiro securityManager --> <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <!-- 指定Shiro驗證使用者登入的類為自定義的Realm(若有多個Realm,可用[realms]屬性代替) --> <property name="realm"> <bean class="com.vkl.mtjg.setting.shiro.WebRealm"/> </property> <!-- shiro快取管理器 --> <property name="cacheManager" ref="shiroEhcacheManager"></property> <property name="sessionManager" ref="sessionManager" /> </bean> <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <!-- Shiro的核心安全介面,這個屬性是必須的 --> <property name="securityManager" ref="securityManager"/> <!-- 要求登入時的連結(可根據專案的URL進行替換),非必須的屬性,預設會找Web工程根目錄下的[/login.jsp] --> <property name="loginUrl" value="/"/> <property name="unauthorizedUrl" value="/unauthorized.do"/> <!-- 過濾鏈定義 --> <property name="filters"> <map> <entry key="kickout" value-ref="kickoutSessionFilter"/> </map> </property> <property name="filterChainDefinitions"> <value> /index.do = anon /agencyLogin.do = anon /login.do = anon /user/doLogin.do = anon /webSocketServer.ws = authc <!-- 首頁 --> /user/index.do = kickout,authc,perms[gljgsy_cx] /user/agencyIndex.do = kickout,authc,perms[jyjgsy_cx] <!-- 預警資訊 --> /user/alertInfo/** = kickout,authc,perms[jkyjrz] <!-- 業務辦理 --> /user/business/** = kickout,authc,perms[ywbl] <!-- 檢驗資訊管理 --> /user/inspect/** = kickout,authc,perms[jyxxgl] <!-- 車輛資訊管理 --> /user/vehicle/** = kickout,authc,perms[clxxgl] <!-- 檢驗機構管理 --> /user/agencyManage/** = kickout,authc,perms[jyjggl] <!-- 統計報表 --> /user/statistics/** = kickout,authc,perms[tjbb] <!-- 使用者管理 --> /user/userManage/** = kickout,authc,perms[yhgl] <!-- 日誌管理 --> /user/log/** = kickout,authc,perms[rzgl] <!-- 系統設定 --> /user/system/** = kickout,authc,perms[xtsz] </value> </property> </bean> <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/> </beans>

伺服器出現異常,具體如下:

嚴重: Servlet.service() for servlet [spring-action] in context with path [/mtjg] threw exception [org.apache.shiro.session.UnknownSessionException: There is no session with id [04a5e4e8-e5fb-4cd4-99b1-4b2bc792cf29]] with root cause
org.apache.shiro.session.UnknownSessionException: There is no session with id [04a5e4e8-e5fb-4cd4-99b1-4b2bc792cf29]
	at org.apache.shiro.session.mgt.eis.AbstractSessionDAO.readSession(AbstractSessionDAO.java:170)
	at org.apache.shiro.session.mgt.eis.CachingSessionDAO.readSession(CachingSessionDAO.java:261)
	at org.apache.shiro.session.mgt.DefaultSessionManager.retrieveSessionFromDataSource(DefaultSessionManager.java:236)
	at org.apache.shiro.session.mgt.DefaultSessionManager.retrieveSession(DefaultSessionManager.java:222)
	at org.apache.shiro.session.mgt.AbstractValidatingSessionManager.doGetSession(AbstractValidatingSessionManager.java:118)
	at org.apache.shiro.session.mgt.AbstractNativeSessionManager.lookupSession(AbstractNativeSessionManager.java:148)
	at org.apache.shiro.session.mgt.AbstractNativeSessionManager.lookupRequiredSession(AbstractNativeSessionManager.java:152)
	at org.apache.shiro.session.mgt.AbstractNativeSessionManager.getAttribute(AbstractNativeSessionManager.java:249)
	at org.apache.shiro.session.mgt.DelegatingSession.getAttribute(DelegatingSession.java:141)
	at org.apache.shiro.session.ProxiedSession.getAttribute(ProxiedSession.java:121)
	at org.apache.shiro.subject.support.DelegatingSubject.getRunAsPrincipalsStack(DelegatingSubject.java:469)
	at org.apache.shiro.subject.support.DelegatingSubject.getPrincipals(DelegatingSubject.java:153)
	at org.apache.shiro.subject.support.DelegatingSubject.getPrincipal(DelegatingSubject.java:149)
	at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSubjectPrincipal(ShiroHttpServletRequest.java:96)
	at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getUserPrincipal(ShiroHttpServletRequest.java:112)
	at org.springframework.web.servlet.FrameworkServlet.getUsernameForRequest(FrameworkServlet.java:1091)
	at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1077)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
最後經過SB式的猜測跟除錯,最終定位到是sessionManager中的屬性sessionDAO導致的(紅色字型標示),把這個屬性去掉後經除錯沒有再出現這個問題了。具體原因後續有時間再細細琢磨。

相關推薦

Spring整合Shiro出現There is no session with id [XXX] with root cause問題的解決方案

最近使用spring + shiro整合的時候出現一個非常頭疼的問題,就是會經常出現There is no session with id [XXX]的問題,而且非常難調試出問題的所在,原始碼也看了關於shiro的部分,但是原因還是找不到。廢話不多說,直接上配置檔案shiro

解決org.apache.shiro.session.UnknownSessionException: There is no session with id的問題

com ebs iss 運行 session共享 tex 童鞋 tor jet 一、背景   最近在整合了Spring+Shiro+Redis實現tomcat集群session共享的問題之後,發布以後運行以後發現老是會出現:org.apache.shiro.session

Shiro報錯org.apache.shiro.session.UnknownSessionException: There is no session with id

錯誤資訊 5:59:12.430 [http-nio-8080-exec-19] DEBUG o.a.shiro.mgt.DefaultSecurityManager - Resolved SubjectContext context session is invalid. Ignor

org.apache.shiro.session.UnknownSessionException: There is no session with id[xx]

問題背景: 借鑑開濤的shiro教程,自己動手實驗下,關於第16章,使用的框架是shiro+spring MVC+maybatis,一啟動就直接拋這個異常。 解決辦法: 1, 配置檔案 中關於Bean:securityManager中property為session

Eclipse中出現there is no staged files

1、 preferences->git->committing 將use stage view to commit instead of commit dialog 的勾去

"There is no tracking information for the current branch" 解決方法

col pan gin ranch eas code pre 解決方法 git 因為新創建的分支push到遠程倉庫後沒有與本地分支關聯,下面語句可以令遠程分支與本地分支關聯起來 git branch --set-upstream-to=origin/release_3

解決Java中There is no getter for property XXX'XXX' in 'class XXX'的問題

src 區分 全路徑 實體類 找到 16px 解決 區分大小寫 ont 當你出現There is no getter for property XXX‘XXX‘ in ‘class XXX‘時,    就是在你的這個類中沒有找到你這個屬性。 檢查兩個地方 1.你的返回值

SpringBoot2.x整合Spring Security5,登陸報錯:There is no PasswordEncoder mapped for the id "null"

解決: 在繼承了WebSecurityConfigurerAdapter的自定義類SecurityConfig上新增一個BCryptPasswordEncoder型別的PasswordEncoder 元件: @EnableWebSecurity //@EnableWeb

【bug】使用spring+struts2註解開發,提示” There is no Action mapped for namespace [/] and action name [xxxxx.action] associated with context path []”

there 提示 就是 技術分享 文件夾路徑 iat class bubuko ring 使用註解開發,通過spring管理struts2容器,配置文件沒有問題,前臺路徑無誤 錯誤提示: There is no Action mapped for namespace [/]

Springboot 出現ibatis:there is no getter for property named 'XX' in class XX的原因及解決辦法

目錄 Dao層書寫的過程中,對映的引數無法對應上。 Dao層書寫的過程中,對映的引數無法對應上。 比如在書寫Mapper層 @Select(“select * from XXX where XX =#{abc};”) 其中abc是Dao層ABC

apt-get update 時出現W: There is no public key available for the following key IDs:

apt-get update 時出現W: There is no public key available for the following key IDs: apt-get install debian-keyring debian-archive-keyring 安裝key源 ap

Spring Security 無法登陸,報錯:There is no PasswordEncoder mapped for the id “null”

編寫好繼承了WebSecurityConfigurerAdapter類的WebSecurityConfig類後,我們需要在configure(AuthenticationManagerBuilder auth) 方法中定義認證用於資訊獲取來源以及密碼校驗規則等。(config

springboot整合mybatis——報錯There is no getter for property named '*' in 'class java.lang.String

There is no getter for property named '*' in 'class java.lang.String',此錯誤之

spring 任務排程中出現懶載入 no session 問題

相信大家在web開發過程中一定遇到過一種情況,Class班級類一對多關聯一個Student學生類,所以為了效能考慮,配置一個lazy-init=true,然後在前臺頁面需要訪問懶載入資料時需要額外配置一個OpenSessionInViewFilter,但是可能並

mybatis加Spring專案: 解決There is no getter for property named '***' in 'class java.lang.String'問題

使用mybatis對映mysql資料庫時,傳入引數為'status',執行報錯為:There is no getter for property named 'status' in 'class java.lang.String 使用'#'作為mybatis的對映標識執行可

SpringBoot2.x整合Security5(完美解決 There is no PasswordEncoder mapped for the id "null")

問題描述 以前做過一次SpringBoot整合Security的專案,但最近重新嘗試SpringBoot整合Security的專案時卻碰到了問題 java.lang.IllegalArgumentException: There is no PasswordEn

Spring Security 報There is no PasswordEncoder mapped for the id "null"

encode row The autowired auto ppa params isp span 查了下發現是spring security 版本在5.0後就要加個PasswordEncoder了 解決辦法 在securityConfig類下加入NoOpP

mybatis 異常 There is no getter for property named 'bizId' in 'class java.lang.Long'

img 技術分享 .com mybatis lan alt nbsp pro 錯誤 mybatis 異常 There is no getter for property named ‘bizId‘ in ‘class java.lang.Long‘ 當使用mybatis進行

Error in library(e1071) : there is no package called 'e1071'

library packages 學習R語言時,在安裝包的時候都是正常的,但當導入包的時候通常會出現下面的情況:libaray(e1071)Error in library(e1071) : there is no package called ‘e1071’網上有些說是包沒有裝全,需要安裝依賴包 ,

There is no getter for property named xxx' in 'class java.lang.xxx'

public med 入參 ren 說明 _id lang list val 在xxxMapper.xml我們使用sql片段來提高sql代碼的復用性,當時新手傳入參數時常常出現這樣的錯誤: There is no getter for property na