TommEE 会话持久存储不起作用

Posted

技术标签:

【中文标题】TommEE 会话持久存储不起作用【英文标题】:TomEE sesison persistance storage not working 【发布时间】:2016-08-07 08:27:12 【问题描述】:

我在 rhel 机器上使用 TomEE plus 1.7.1。 我已经为持久存储设置了 jdbc 存储,以将会话数据存储在 mysql 数据库中。 jdbc 商店不在 rhel 机器上运行。即使文件中的持久性也不起作用。 以下是我所做的设置。

在/conf/context.xml中添加了这个

<Manager className="org.apache.catalina.session.PersistentManager"
        maxIdleBackup="0">
  <Store className="org.apache.catalina.session.JDBCStore"
         connectionURL="jdbc:mysql://dbservername:3306/someName?user=[user]&amp;password=[pass]"
         driverName="com.mysql.jdbc.Driver"
         sessionAppCol="app_name"
         sessionDataCol="session_data"
         sessionIdCol="session_id"
         sessionLastAccessedCol="last_access"
         sessionMaxInactiveCol="max_inactive"
         sessionTable="TOMCAT_SESSIONS"
         sessionValidCol="valid_session"/>
</Manager>

我有一个包含以下内容的 TomEE 启动脚本。第2行与jdbc store有关

export JAVA_OPTS="-Djava.awt.headless=true -Dawt.toolkit=sun.awt.HToolkit"
export CATALINA_OPTS="-Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true"
sh catalina.sh start

在mysql的表中创建了以下内容

created following table
 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)
);

在 /lib 中添加了 mysql-connector-java.jar 观察到以下错误

观察到的错误-

对于部署在 apache 中的每个应用程序,我都会遇到这些错误

SEVERE: Error manager.start()
org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.session.PersistentManager[/tomee]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5499)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
        at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1247)
        at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1898)
        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[/tomee]]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.session.PersistentManagerBase.startInternal(PersistentManagerBase.java:864)
        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:961)
        at org.apache.catalina.session.JDBCStore.getConnection(JDBCStore.java:893)
        at org.apache.catalina.session.JDBCStore.startInternal(JDBCStore.java:1064)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 14 more



SEVERE: Error manager.start()
org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.session.PersistentManager[/myAppname1]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5499)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
        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[/myAppname1]]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.session.PersistentManagerBase.startInternal(PersistentManagerBase.java:864)
        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:961)
        at org.apache.catalina.session.JDBCStore.getConnection(JDBCStore.java:893)
        at org.apache.catalina.session.JDBCStore.startInternal(JDBCStore.java:1064)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 14 more



        SEVERE: Error manager.start()
org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.session.PersistentManager[/myAppname2]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5499)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
        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[/myAppname2]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.session.PersistentManagerBase.startInternal(PersistentManagerBase.java:864)
        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:961)
        at org.apache.catalina.session.JDBCStore.getConnection(JDBCStore.java:893)
        at org.apache.catalina.session.JDBCStore.startInternal(JDBCStore.java:1064)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 14 more


        SEVERE: Error manager.start()
org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.session.PersistentManager[/myAppname3]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5499)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
        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[/myAppname3]]]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
        at org.apache.catalina.session.PersistentManagerBase.startInternal(PersistentManagerBase.java:864)
        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:961)
        at org.apache.catalina.session.JDBCStore.getConnection(JDBCStore.java:893)
        at org.apache.catalina.session.JDBCStore.startInternal(JDBCStore.java:1064)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        ... 14 more

【问题讨论】:

【参考方案1】:

不推荐使用 JDBC 会话持久性。甚至 Tomcat 手册也建议不要这样做。它不稳定、缓慢且容易出错。

驱动程序似乎出了点问题:http://grepcode.com/file/repo1.maven.org/maven2/org.apache.tomcat/tomcat-catalina/7.0.55/org/apache/catalina/session/JDBCStore.java#961

我会先确保它在您的类路径中。之后,在调试器中设置断点并查看实际为 null 的内容。

【讨论】:

【参考方案2】:

就我而言,这是因为我使用了错误的 JDBC URL,尤其是方案部分。

我用过:

postgres://

(对于psql 可以,但对于 JDBC 则不行)。正确的是:

jdbc:postgresql://

【讨论】:

以上是关于TommEE 会话持久存储不起作用的主要内容,如果未能解决你的问题,请参考以下文章

存储访问框架持久权限不起作用

Spring安全令牌持久性存储不起作用

快速护照会话不起作用

当指定存储级别时,在 pyspark2 中持久化数据帧不起作用。我究竟做错了啥?

在数据库表中存储会话不起作用(使用 Zend_Session_SaveHandler_DbTable)

会话 cookie 在 Electron 中不起作用