ActiveMQ 5.8:无法加载JDBC驱动程序类'oracle.jdbc.driver.OracleDriver'

时间:2013-09-24 12:17:45

标签: java oracle jdbc activemq

我正在尝试将ActiveMQ persitenceAdapter设置为Oracle 11g(11.2)数据库。 通过Tanuki包装器启动ActiveMQ时,我得到的是无法加载JDBC驱动程序类'oracle.jdbc.driver.OracleDriver'的异常。我在网上搜索了几个小时而没有找到任何相关的答案。我的类路径是正确的。

我觉得Tanuki包装器没有考虑我的类路径定制。

如果您发现任何错误或为我提供了一个有效的例子,请告诉我

我的设置是:
activemq.xml中

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="test1" dataDirectory="/path/to/existing">
    ...
    <persistenceAdapter>
        <jdbcPersistenceAdapter dataDirectory="/path/to/existing/activemq-data" dataSource="#oracle-ds"/>
    </persistenceAdapter>
    ...
</broker>

<bean id="oracle-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value=" jdbc:oracle:thin:@db.domain:1521:DEV01 "/>
    <property name="username" value="username"/>
    <property name="password" value="password"/>
    <property name="poolPreparedStatements" value="true"/>
</bean>

<import resource="jetty.xml"/>


wrapper.conf

wrapper.java.classpath.1=%ACTIVEMQ_HOME%/bin/wrapper.jar
wrapper.java.classpath.2=%ACTIVEMQ_HOME%/bin/activemq.jar
wrapper.java.classpath.3=%ACTIVEMQ_HOME%/lib/*
wrapper.java.classpath.4=%ACTIVEMQ_HOME%/lib/optional/ojdbc6.jar

完整堆栈跟踪

2013-09-24 14:07:15,973 | ERROR | Failed to load: class path resource [activemq.xml], reason: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception 
is java.io.IOException: Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL ' jdbc:oracle:thin:@db.domain:1521:DEV01 ' | org.apache.activemq.xbean.XBeanBrokerFactory | WrapperSimpleAppMain
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.io.IOException: Cannot create
 JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL ' jdbc:oracle:thin:@db.domain:1521:DEV01 '
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:605)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
        at org.apache.xbean.spring.context.ResourceXmlApplicationContext.(ResourceXmlApplicationContext.java:64)
        at org.apache.xbean.spring.context.ResourceXmlApplicationContext.(ResourceXmlApplicationContext.java:52)
        at org.apache.activemq.xbean.XBeanBrokerFactory$1.(XBeanBrokerFactory.java:101)
        at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:101)
        at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:65)
        at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)
        at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)
        at org.apache.activemq.console.command.StartCommand.startBroker(StartCommand.java:125)
       at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:84)
        at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
        at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:150)
        at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
        at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)
        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:601)
        at org.apache.activemq.console.Main.runTaskClass(Main.java:262)
        at org.apache.activemq.console.Main.main(Main.java:115)
        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:601)
        at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)
        at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.IOException: Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL ' jdbc:oracle:thin:@db.domain:1521:DEV01 '
        at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:45)
        at org.apache.activemq.store.jdbc.TransactionContext.getConnection(TransactionContext.java:68)
        at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.loadAdapter(JDBCPersistenceAdapter.java:434)
       at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.createAdapter(JDBCPersistenceAdapter.java:417)
        at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.getAdapter(JDBCPersistenceAdapter.java:366)
        at org.apache.activemq.store.jdbc.JDBCPersistenceAdapter.init(JDBCPersistenceAdapter.java:288)
        at org.apache.activemq.broker.LockableServiceSupport.preStart(LockableServiceSupport.java:79)
        at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:54)
        at org.apache.activemq.broker.BrokerService.doStartPersistenceAdapter(BrokerService.java:598)
        at org.apache.activemq.broker.BrokerService.startPersistenceAdapter(BrokerService.java:587)
        at org.apache.activemq.broker.BrokerService.start(BrokerService.java:552)
        at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:60)
        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:601)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
        ... 34 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'oracle.jdbc.driver.OracleDriver' for connect URL ' jdbc:oracle:thin:@db.domain:1521:DEV01 '
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at org.apache.activemq.store.jdbc.TransactionContext.getConnection(TransactionContext.java:58)
        ... 51 more
Caused by: java.sql.SQLException: No suitable driver
        at java.sql.DriverManager.getDriver(DriverManager.java:289)
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
        ... 54 more

1 个答案:

答案 0 :(得分:1)

我正在回答我自己的问题:

正如Alexey Odintsov指出的那样,我犯了一个错字 要解决此问题,请在activemq.xml文件中更改行

<property name="url" value=" jdbc:oracle:thin:@db.domain:1521:DEV01 "/>

删除值引号

中的前导和尾随空格
<property name="url" value="jdbc:oracle:thin:@db.domain:1521:DEV01"/>