无论我在哪里指定,Tomcat 7都无法加载ojdbc6.jar

时间:2013-01-19 04:36:26

标签: spring tomcat jdbc oracle11g web-deployment-project

这是一个真正考虑我的耐心。我有一个简单的Spring 3.1 + Jersey应用程序,我正在尝试使用ojdbc6.jar作为我的数据源。不幸的是,无论我尝试什么,它都永远找不到“oracle.jdbc.driver.OracleDriver”类。

我打开了类加载器跟踪,我可以看到正在加载的ojdbc6.jar:

[Loaded oracle.jdbc.driver.OracleDriver from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.OracleDriver from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded java.sql.SQLException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.Wrapper from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.Connection from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded javax.management.InstanceAlreadyExistsException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded oracle.jdbc.driver.OracleDriverExtension from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded java.sql.DriverInfo from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded oracle.jdbc.driver.OracleDriver$1 from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.driver.ClassRef from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.driver.ClassRef$XMLTypeClassRef from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.driver.DiagnosabilityMXBean from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.driver.OracleDiagnosabilityMBean from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded javax.management.StandardMBean$MBeanInfoSafeAction from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded oracle.jdbc.driver.DatabaseError from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.driver.OracleSQLException from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded java.lang.StringIndexOutOfBoundsException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded oracle.jdbc.driver.SQLStateMapping from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded java.sql.SQLNonTransientException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLTransientException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLDataException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLFeatureNotSupportedException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLIntegrityConstraintViolationException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLInvalidAuthorizationSpecException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLNonTransientConnectionException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLSyntaxErrorException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLTimeoutException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLTransactionRollbackException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLTransientConnectionException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLClientInfoException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded java.sql.SQLRecoverableException from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar]
[Loaded oracle.jdbc.driver.SQLStateMapping$Tokenizer from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.driver.Message from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.driver.Message11 from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.internal.ObjectDataFactory from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.sql.ORADataFactory from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.sql.AnyDataFactory from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.internal.ObjectData from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.sql.ORAData from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.sql.TypeDescriptorFactory from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.OracleConnection from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.internal.OracleConnection from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.internal.ClientDataSupport from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.OracleConnectionWrapper from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.driver.OracleConnection from file:/opt/tomcat7/lib/ojdbc6.jar]
[Loaded oracle.jdbc.driver.PhysicalConnection from file:/opt/tomcat7/lib/ojdbc6.jar]

但是当我尝试我的网络服务电话时,我得到以下内容:

SEVERE: Servlet.service() for servlet [oraclepoc] in context with path [/oraclepoc] threw exception
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '"oracle.jdbc.driver.OracleDriver"/>'
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674)
    at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:729)
    at com.company.sims.oraclepoc.dao.ProcessStatusDaoImpl.getStatusByProcessID(ProcessStatusDaoImpl.java:15)
    at com.company.sims.oraclepoc.resources.ProcessStatusRestController.getEMSStatusByProcessID_XML(ProcessStatusRestController.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '"oracle.jdbc.driver.OracleDriver"/>'
    at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    ... 43 more
Caused by: java.lang.ClassNotFoundException: "oracle.jdbc.driver.OracleDriver"/>
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
    ... 47 more
Jan 18, 2013 11:24:30 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [oraclepoc] in context with path [/oraclepoc] threw exception
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '"oracle.jdbc.driver.OracleDriver"/>'
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:573)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674)
    at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:729)
    at com.company.sims.oraclepoc.dao.ProcessStatusDaoImpl.getStatusByProcessID(ProcessStatusDaoImpl.java:15)
    at com.company.sims.oraclepoc.resources.ProcessStatusRestController.getEMSStatusByProcessID_XML(ProcessStatusRestController.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class '"oracle.jdbc.driver.OracleDriver"/>'
    at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    ... 43 more
Caused by: java.lang.ClassNotFoundException: "oracle.jdbc.driver.OracleDriver"/>
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
    ... 47 more

我的应用程序上下文XML文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    <context:component-scan base-package="com.company.sims.oraclepoc"/>
    <context:annotation-config/>
    <bean id="propertyConfigurer" 
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>jdbc.properties</value>
        </property>
    </bean>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close">
        <property name="driverClassName">
            <value>${jdbc.driver}</value>
        </property>
        <property name="url">
            <value>${jdbc.url}</value>
        </property>
        <property name="username">
            <value>${jdbc.user}</value>
        </property>
        <property name="password">
            <value>${jdbc.password}</value>
        </property>
    </bean>
    <bean id="processStatusDao" class="com.company.sims.oraclepoc.dao.ProcessStatusDaoImpl">
        <property name="dataSource" ref="dataSource" />
    </bean>  
</beans>

我的jdbc.properties文件:

jdbc.driver="oracle.jdbc.driver.OracleDriver"/>
jdbc.url="jdbc:oracle:thin:@10.10.10.10:1522:db"/>
jdbc.user="USER"/>
jdbc.password="password"/>

我已经尝试将它放在WEB-INF / lib目录中以及Tomcat的LIB目录中。两次尝试都失败了。

5 个答案:

答案 0 :(得分:6)

我认为它是一个类加载问题。 我能想到的是:

  • 两个ojdbc.jars在您的类路径中可访问,一个在tomcat / lib中,另一个在WEB-INF / lib中
  • 两个ojdbc.jars在您的类路径中可访问,一个在JRE ext文件夹中,另一个在WEB-INF / lib中

或类似的东西。

确保类路径中只有一个JDBC驱动程序。您可以删除WEB-INF / lib中的那个以查看您的应用程序是否有效。

答案 1 :(得分:4)

oracle.jdbc.driver.OracleDriver类已弃用多年,且为removed from ojdbc6.jar in Oracle JDBC Drivers release 11.1.0.7.0

您应该使用oracle.jdbc.OracleDriver代替。

答案 2 :(得分:1)

你确定.jar在正确的位置吗?例如,在这种情况下,它需要位于nTomcat“common / lib”,而不是“app / lib”:

答案 3 :(得分:1)

事实证明,经过一夜的休息和一段时间之后,我带领this link here in SO.结果我的jdbc.properties文件对我的Oracle实例构建得很糟糕,但对我的Sybase实例来说却是正确的。感谢大家的帮助。向我投票,因为我很荒谬。

答案 4 :(得分:0)

我正在使用Jetbrains IntelliJ IDE。我选择了设置 - 构建,执行,部署 - 构建工具 - Maven - Runner ,并在JRE ComboBox中选择了高于1.6的Java版本。错误消失了。