Estoy intentando configurar Tomcat 8.5.9 para que arranque en modo de sesión persistente y almacene la sesión en MySql. Para ello he seguido el procedimiento descrito en la documentación de Tomcat:
- Crear la tabla tomcat_sessions, tal como indican en la documentación:
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) );
- En segundo lugar, he introducido la librería mysql-connector-java-5.1.40-bin.jar en el classpath de tomcat.
Finalmente he modificado el fichero context.xml del siguiente modo:
<?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>
Cuando ejecuto Tomcat, salta el siguiente 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