I am trying to configure Tomcat 8.5.9 to boot in persistent session mode and store the session in MySql. For this I have followed the procedure described in the Tomcat documentation :
- Create the tomcat_sessions table, as indicated in the documentation:
create table tomcat_sessions ( session_id varchar(100) not null primary key, valid_session char(1) not null, max_inactive int not null, last_access bigint not null, app_name varchar(255), session_data mediumblob, KEY kapp_name(app_name) );
- Second, I have inserted the mysql-connector-java-5.1.40-bin.jar library into the tomcat classpath.
Finally I have modified the context.xml file as follows:
<?xml version="1.0" encoding="UTF-8"?> <Context> <WatchedResource>WEB-INF/web.xml</WatchedResource> <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> <Manager className="org.apache.catalina.session.PersistentManager" debug="0" maxActiveSessions="-1" maxIdleBackup="-1" minIdleSwap="-1" maxIdleSwap="-1" processExpiresFrequency="1" saveOnRestart='true' > <Store className="org.apache.catalina.session.JDBCStore" connectionName="root" connectionPassword="password" connectionURL="jdbc:mysql://localhost:3306/tomcat" driverName="com.mysql.jdbc.Driver" /> </Manager> </Context>
When I run Tomcat, I get the following error:
16-Jan-2017 11:55:04.597 GRAVE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal The session manager failed to start
org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.session.PersistentManager[/manager]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5206)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1107)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1841)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.session.JDBCStore[org.apache.catalina.session.PersistentManager[/manager]]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.session.PersistentManagerBase.startInternal(PersistentManagerBase.java:847)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 12 more
Caused by: java.lang.NullPointerException
at org.apache.catalina.session.JDBCStore.open(JDBCStore.java:906)
at org.apache.catalina.session.JDBCStore.getConnection(JDBCStore.java:839)
at org.apache.catalina.session.JDBCStore.startInternal(JDBCStore.java:1001)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 14 more
According to the source code, line 906 where you have the NullPointer is the one that sets the autocommit:
So the Driver seems to be finding it fine, but it can't create the connection. Make sure the connection url, port, user and passwd are correct.