1

I am working on adding session persistence in Tomcat with MySQL, but unfortunately it is not working. Nothing in database. I am trying to save session information so that users are logged in even after tomcat restart. This is the configuration I have :

table :

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&amp;password=PASSWORD&amp;useSSL=false"
sessionTable="tomcat$sessions"
sessionIdCol="id"
sessionDataCol="data"
sessionValidCol="valid"
sessionMaxInactiveCol="maxinactive"
sessionLastAccessedCol="lastaccess"
checkInterval="60"
debug="99" />
</Manager>

logging.properties :

# 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.out :

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"
We are Borg
  • 177
  • 1
  • 18
  • May need to check system properties https://tomcat.apache.org/tomcat-7.0-doc/config/manager.html – Schrute Mar 22 '17 at 21:45
  • @Schrute : Sorry for the late reply, which system properties you mean? Thank you. – We are Borg Apr 12 '17 at 10:40
  • @Schrute : I also checked the database, and noticed that there are no entries in the DB. What am I doing wrong? – We are Borg Apr 12 '17 at 11:14
  • The options seem ok - but maybe check the driver name: http://stackoverflow.com/questions/5808160/what-is-the-jdbc-driver-org-gjt-mm-mysql-driver-for – Schrute Apr 12 '17 at 19:37
  • @Schrute : Still nothing, do I need tracking-mode = COOKIE in web.xml for this to work? Thank you. – We are Borg Apr 13 '17 at 07:53
  • At this point looks like the best option is to turn on logging on MySQL and look for any messages that may be related to the connection, statements etc. – Schrute Apr 17 '17 at 16:57

0 Answers0