shiro session 失效時間該如何弄

蟲二來了 4周前 177 瀏覽

org.apache.shiro.session.UnknownSessionException: There is no session with id [8c42bd6e-6a89-4069-8b36-9cac1ed836bc] at org.apache.shiro.session.mgt.eis.AbstractSessionDAO.readSession(AbstractSessionDAO.java:170) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.session.mgt.DefaultSessionManager.retrieveSessionFromDataSource(DefaultSessionManager.java:236) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.session.mgt.DefaultSessionManager.retrieveSession(DefaultSessionManager.java:222) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.session.mgt.AbstractValidatingSessionManager.doGetSession(AbstractValidatingSessionManager.java:118) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.session.mgt.AbstractNativeSessionManager.lookupSession(AbstractNativeSessionManager.java:148) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.session.mgt.AbstractNativeSessionManager.lookupRequiredSession(AbstractNativeSessionManager.java:152) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.session.mgt.AbstractNativeSessionManager.removeAttribute(AbstractNativeSessionManager.java:263) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.session.mgt.DelegatingSession.removeAttribute(DelegatingSession.java:159) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.session.mgt.DelegatingSession.setAttribute(DelegatingSession.java:149) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.session.ProxiedSession.setAttribute(ProxiedSession.java:128) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.web.servlet.ShiroHttpSession.setAttribute(ShiroHttpSession.java:202) ~[shiro-web-1.3.2.jar:1.3.2] at com.sxyscms.core.security.CmsAuthenticationFilter.executeLogin(CmsAuthenticationFilter.java:103) ~[classes/:na] at org.apache.shiro.web.filter.authc.FormAuthenticationFilter.onAccessDenied(FormAuthenticationFilter.java:154) ~[shiro-web-1.3.2.jar:1.3.2] at org.apache.shiro.web.filter.AccessControlFilter.onAccessDenied(AccessControlFilter.java:133) ~[shiro-web-1.3.2.jar:1.3.2] at com.sxyscms.core.security.CmsAuthenticationFilter.onPreHandle(CmsAuthenticationFilter.java:132) ~[classes/:na] at org.apache.shiro.web.filter.PathMatchingFilter.isFilterChainContinued(PathMatchingFilter.java:203) ~[shiro-web-1.3.2.jar:1.3.2] at org.apache.shiro.web.filter.PathMatchingFilter.preHandle(PathMatchingFilter.java:178) ~[shiro-web-1.3.2.jar:1.3.2] at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:131) ~[shiro-web-1.3.2.jar:1.3.2] at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) ~[shiro-web-1.3.2.jar:1.3.2] at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) ~[shiro-web-1.3.2.jar:1.3.2] at com.sxyscms.core.support.BackSiteFilter.doFilter(BackSiteFilter.java:50) ~[classes/:na] at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) ~[shiro-web-1.3.2.jar:1.3.2] at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) ~[shiro-web-1.3.2.jar:1.3.2] at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) ~[shiro-web-1.3.2.jar:1.3.2] at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) ~[shiro-core-1.3.2.jar:1.3.2] at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) ~[shiro-web-1.3.2.jar:1.3.2] at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) ~[shiro-web-1.3.2.jar:1.3.2] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:347) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:263) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:178) ~[spring-orm-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.17.RELEASE.jar:4.3.17.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) ~[tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) [tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) [tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) [tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) [tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452) [tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087) [tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) [tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1756) [tomcat-embed-core-7.0.73.jar:7.0.73] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1715) [tomcat-embed-core-7.0.73.jar:7.0.73] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_92] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_92] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-7.0.73.jar:7.0.73] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_92]

下面代碼 @Bean public DefaultWebSessionManager sessionManager(){ DefaultWebSessionManager sessionManager=new DefaultWebSessionManager();

    //全局會話超時時間(單位毫秒),默認30分鐘  暫時設置為10秒鐘 用來測試
    sessionManager.setGlobalSessionTimeout(10000);
    //是否開啟刪除無效的session對象  默認為true
    sessionManager.setDeleteInvalidSessions(true);
    //是否開啟定時調度器進行檢測過期session 默認為true
    sessionManager.setSessionValidationSchedulerEnabled(true);
    //設置session失效的掃描時間, 清理用戶直接關閉瀏覽器造成的孤立會話 默認為 1個小時
    //設置該屬性 就不需要設置 ExecutorServiceSessionValidationScheduler 底層也是默認自動調用ExecutorServiceSessionValidationScheduler
    //暫時設置為 5秒 用來測試
    sessionManager.setSessionValidationInterval(5000);
    return sessionManager;
}
評論 編輯
1 回答

我來回答

請先登錄再回答問題
點擊查看大圖插件 宝山区| 中江县| 义马市| 古田县| 惠水县| 平塘县| 长岭县| 大埔县| 浮山县| 尉氏县| 固原市| 乡宁县| 嘉义县| 疏附县| 平山县| 镇康县| 赣州市| 洪洞县| 大足县| 米泉市| 临海市| 景洪市| 图木舒克市| 策勒县| 安远县| 库伦旗| 肥城市| 衡山县| 香格里拉县| 石渠县| 利辛县| 扎鲁特旗| 盖州市| 马龙县| 新民市| 定南县| 平邑县| 淮安市| 泰来县| 隆化县| 清河县| 宝山区| 中江县| 义马市| 古田县| 惠水县| 平塘县| 长岭县| 大埔县| 浮山县| 尉氏县| 固原市| 乡宁县| 嘉义县| 疏附县| 平山县| 镇康县| 赣州市| 洪洞县| 大足县| 米泉市| 临海市| 景洪市| 图木舒克市| 策勒县| 安远县| 库伦旗| 肥城市| 衡山县| 香格里拉县| 石渠县| 利辛县| 扎鲁特旗| 盖州市| 马龙县| 新民市| 定南县| 平邑县| 淮安市| 泰来县| 隆化县| 清河县|