在tomcat context.xml中指定Oracle DB / Schema名称

时间:2014-03-18 21:12:58

标签: java xml oracle tomcat jdbc

我正在尝试在Tomcat中添加JDBC Session Persistence,如下所述:Tomcat Link 我在my_schema数据库/模式中在Oracle中创建了一个会话表,并尝试将其映射到Tomcat context.xml中。我的映射如下:

   <Resource name="jdbc/sessions" auth="Container" type="javax.sql.DataSource"
    username="test_user"
    password="test_user"
    driverClassName="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=my-host-blah.com)(PORT=1234))(ADDRESS=(PROTOCOL=TCP)(HOST=my-host-blah.com)(PORT=1244)))(CONNECT_DATA=(SERVICE_NAME=someservice)))"
    maxActive="20"
    maxIdle="10"
    validationQuery="select 1" />

<Manager className="org.apache.catalina.session.PersistentManager"
    distributable="true"  processExpiresFrequency="3" maxIdleBackup="1" >
    <Store className="org.apache.catalina.session.JDBCStore"
        dataSourceName="jdbc/sessions"
        sessionAppCol="app_name" sessionDataCol="session_data" sessionIdCol="session_id"
        sessionLastAccessedCol="last_access" sessionMaxInactiveCol="max_inactive"
        sessionTable="tomcat_sessions" sessionValidCol="valid_session" />
</Manager>

但是上面的配置在tomcat启动时导致NullPointerException。我知道url,用户名和密码是正确的,因为如果我编写一个简单的Java程序并连接/查询my_schema.tomcat_sessions表,它就可以正常工作。但我不确定如何在上面的配置中指定特定的DB /模式名称。我得到的例外情况如下:

  

SEVERE:错误manager.start()   显示java.lang.NullPointerException           at java.lang.Class.forName0(Native Method)           at java.lang.Class.forName(Class.java:190)           在org.apache.catalina.session.JDBCStore.open(JDBCStore.java:861)           在org.apache.catalina.session.JDBCStore.getConnection(JDBCStore.java:833)           在org.apache.catalina.session.JDBCStore.start(JDBCStore.java:968)           在org.apache.catalina.session.PersistentManagerBase.start(PersistentManagerBase.java:995)           在org.apache.catalina.core.StandardContext.start(StandardContext.java:4713)           在org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)           在org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)           在org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)           在org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)           在org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)           在org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)           在org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)           在org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)           在org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)           在org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)           在org.apache.catalina.core.StandardHost.start(StandardHost.java:840)           在org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)           在org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)           在org.apache.catalina.core.StandardService.start(StandardService.java:525)           在org.apache.catalina.core.StandardServer.start(StandardServer.java:754)           在org.apache.catalina.startup.Catalina.start(Catalina.java:595)           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)           at java.lang.reflect.Method.invoke(Method.java:606)           在org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)           在org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

我想知道问题是否因为我没有在任何地方指定数据库/模式名称? 我尝试将driverClassName更改为oracle.jdbc.OracleDriver,但没有运气。 我确保$ TOMCAT_HOME / lib有ojdbc6.jar文件。 还有其他想法/想法吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试在context.xml中使用以下内容:

<Manager className="org.apache.catalina.session.PersistentManager"
         maxIdleBackup="10">
  <Store className="org.apache.catalina.session.JDBCStore"
         connectionURL="jdbc:oracle:thin:USERNAME/PASSWORD@//HOSTNAME/SID"
         driverName="oracle.jdbc.driver.OracleDriver"
         sessionAppCol="app_name"
         sessionDataCol="session_data"
         sessionIdCol="session_id"
         sessionLastAccessedCol="last_access"
         sessionMaxInactiveCol="max_inactive"
         sessionTable="tomcat_sessions"
         sessionValidCol="valid_session" />
</Manager>

确保替换connectionURL属性中的值,并将Oracle JDBC驱动程序(ojdbc6.jar)添加到tomcat的lib目录中。