我正在使用 MySQL 在 Tomcat 中添加会话持久性,但不幸的是它不起作用。数据库中没有任何内容。我试图保存会话信息,以便用户即使在 tomcat 重新启动后也能登录。这是我的配置:
桌子 :
create database tomcat;
create table tomcat$sessions
(
id varchar(100) not null primary key,
valid char(1) not null,
maxinactive int not null,
lastaccess bigint,
data mediumblob
);
context.xml:
<Manager className="org.apache.catalina.session.PersistentManager" debug="3" saveOnRestart="true" maxActiveSessions="-1"
minIdleSwap="-1" maxIdleSwap="-1" maxIdleBackup="-1">
<Store className="org.apache.catalina.session.JDBCStore"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost/tomcat?user=USERNAME&password=PASSWORD&useSSL=false"
sessionTable="tomcat$sessions"
sessionIdCol="id"
sessionDataCol="data"
sessionValidCol="valid"
sessionMaxInactiveCol="maxinactive"
sessionLastAccessedCol="lastaccess"
checkInterval="60"
debug="99" />
</Manager>
日志记录.属性:
# To see debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE
org.apache.catalina.session.PersistentManager.level = ALL
org.apache.catalina.session.PersistentManager.useParentHandlers = true
org.apache.catalina.session.level = ALL
org.apache.catalina.session.useParentHandlers = true
catalina.输出:
Feb 17, 2017 2:24:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: Start expire sessions PersistentManager at 1487337861731 sessioncount 1
Feb 17, 2017 2:24:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: End expire sessions PersistentManager processingTime 16 expired sessions: 0
Feb 17, 2017 2:25:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: Start expire sessions PersistentManager at 1487337921759 sessioncount 1
Feb 17, 2017 2:25:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: End expire sessions PersistentManager processingTime 13 expired sessions: 0
Feb 17, 2017 2:26:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: Start expire sessions PersistentManager at 1487337981776 sessioncount 1
Feb 17, 2017 2:26:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: End expire sessions PersistentManager processingTime 9 expired sessions: 0
Feb 17, 2017 2:27:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: Start expire sessions PersistentManager at 1487338041789 sessioncount 1
Feb 17, 2017 2:27:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: End expire sessions PersistentManager processingTime 16 expired sessions: 0
Feb 17, 2017 2:28:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: Start expire sessions PersistentManager at 1487338101809 sessioncount 1
Feb 17, 2017 2:28:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: End expire sessions PersistentManager processingTime 15 expired sessions: 0
Feb 17, 2017 2:29:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: Start expire sessions PersistentManager at 1487338161833 sessioncount 1
Feb 17, 2017 2:29:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: End expire sessions PersistentManager processingTime 15 expired sessions: 0
Feb 17, 2017 2:30:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: Start expire sessions PersistentManager at 1487338221852 sessioncount 1
Feb 17, 2017 2:30:21 PM org.apache.catalina.session.PersistentManagerBase processExpires
FINE: End expire sessions PersistentManager processingTime 14 expired sessions: 0
Feb 17, 2017 2:30:34 PM org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
catalina.sh:
CATALINA_OPTS="$CATALINA_OPTS -server -Xms3g -XX:+UseParallelGC -XX:ParallelGCThreads=2 -Dspring.security.strategy=MODE_INHERITABLETHREADLOCAL -Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true"