Maven-Camel-Spring-Oracle: Error creating bean - java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]

user3049941 picture user3049941 · Nov 29, 2013 · Viewed 18.6k times · Source

I'm getting this error since yesterday, and even though I've tried everything that came to my mind or I found searching on the internet, I can't solve it. Context: java 6, Spring 3.1.4, camel 2.11.1, Oracle driver 10.2.0.2.

I have this bean in camel context file:

<bean id="myDataSource"  class="**org.springframework.jdbc.datasource.DriverManagerDataSource**">
  <property name="driverClassName" value="**oracle.jdbc.driver.OracleDriver"**/>
  <property name="url" value="jdbc:...."/>
  <property name="username" value="userhere"/>
  <property name="password" value="passwordhere"/>
</bean> 

I've also tried with this class for the bean: class="org.apache.commons.dbcp.BasicDataSource" And a bean somewhere else using this bean. I have this in POM (By the way, I brought this dependency from another project that points to the same database, so it's the correct version):

<dependency>
  <groupId>com.oracle</groupId>
  <artifactId>ojdbc14</artifactId>
  <version>10.2.0.2</version> 
  <scope>provided</scope>
</dependency>

I also have this, because of different thing I've tried to make it work:

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-jdbc</artifactId>
  <version>2.11.1</version>
</dependency>   
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>3.1.4.RELEASE</version>
</dependency>
<dependency>
  <groupId>commons-dbcp</groupId>
  <artifactId>commons-dbcp</artifactId>
  <version>1.4</version>
</dependency>
  • The connection data (url, user and password), it's verified, and it's correct for each one of the environments' db I tried to connect.
  • I can see the ojdbc14 jar in Maven dependencies, I also see it when doing "maven run" with debug output enabled: [DEBUG] Adding project dependency artifact: ojdbc14 to classpath
  • I can see the class oracle.jdbc.driver.OracleDriver inside the jar.

Yet, I'm getting these errors everytime:

  • When using class="org.apache.commons.dbcp.BasicDataSource" as dataSource class: class="org.apache.commons.dbcp.BasicDataSource"

            [29 Nov 2013 13:39:03,257][e) thread #0 - timer://kickoff] DefaultErrorHandler            ERROR Failed delivery for (MessageId: ID-vpar-alcantara-51044-1385743141288-0-1 on ExchangeId: ID-vpar-alcantara-51044-1385743141288-0-2). Exhausted after delivery attempt: 1 caught: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
            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.apache.camel.component.jdbc.JdbcProducer.processingSqlBySettingAutoCommit(JdbcProducer.java:76)
                at org.apache.camel.component.jdbc.JdbcProducer.process(JdbcProducer.java:63)
                at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)
                at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)
                at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.processor.interceptor.BacklogTracerInterceptor.process(BacklogTracerInterceptor.java:84)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:391)
                at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:273)
                at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:335)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
                at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
                at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
                at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
                at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
                at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:135)
                at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:63)
                at java.util.TimerThread.mainLoop(Timer.java:555)
                at java.util.TimerThread.run(Timer.java:505)
            Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
                at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
                at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
                at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
                ... 46 more
            [29 Nov 2013 13:39:03,265][e) thread #0 - timer://kickoff] TimerConsumer                  WARN  Error processing exchange. Exchange[Message: select vendor_style from supplier_ingest_style where  bluefly_product_color is not null]. Caused by: [org.apache.commons.dbcp.SQLNestedException - Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver']
            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.apache.camel.component.jdbc.JdbcProducer.processingSqlBySettingAutoCommit(JdbcProducer.java:76)
                at org.apache.camel.component.jdbc.JdbcProducer.process(JdbcProducer.java:63)
                at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)
                at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)
                at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.processor.interceptor.BacklogTracerInterceptor.process(BacklogTracerInterceptor.java:84)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:391)
                at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:273)
                at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:335)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
                at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
                at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
                at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
                at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
                at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
                at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
                at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
                at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
                at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:135)
                at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:63)
                at java.util.TimerThread.mainLoop(Timer.java:555)
                at java.util.TimerThread.run(Timer.java:505)
            Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
                at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
                at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
                at java.security.AccessController.doPrivileged(Native Method)
                at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
                at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1420)
    
  • When using class="org.springframework.jdbc.datasource.DriverManagerDataSource"

            java.lang.reflect.InvocationTargetException
                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)
                at org.apache.camel.maven.RunMojo$1.run(RunMojo.java:459)
                at java.lang.Thread.run(Thread.java:744)
            Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDataSource' defined in file [C:\GITWorkspace\vendorIngestion\target\classes\META-INF\spring\camel-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
            PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
                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:607)
                at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
                at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
                at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
                at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
                at org.apache.camel.spring.Main.createDefaultApplicationContext(Main.java:186)
                at org.apache.camel.spring.Main.doStart(Main.java:140)
                at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
                at org.apache.camel.main.MainSupport.run(MainSupport.java:148)
                at org.apache.camel.main.MainSupport.run(MainSupport.java:343)
                at org.apache.camel.spring.Main.main(Main.java:73)
                ... 6 more
            Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
            PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
                at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
                at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393)
    

    In both messages it can't load OracleDriver apparently, although I can't see why exactly. The first one says ClassNotfoundException, and the second one java.lang.IllegalStateException.

Right now I'm running with maven pluggin in Eclipse, I also tried, just in case but knowing that's not a solution when running with Maven, to add the ojdbc jar to the eclipse classpath. But nothing worked. The oracle driver version is correct for our Orcale, the url is correct, so the user and password, I've tried to point to each one of the environments db I have access (local, dev, qa, staging). Nothing worked.

Anyone has any idea why it can't find or load OracleDriver when in fact it's adding the jar to the classpath?

Answer

NickDK picture NickDK · Nov 29, 2013

Are you running this app on an application server? If the server doesn't have the JDBC driver on it's classpath try setting the scope to default (compile) for the Oracle driver dependency, since it's the default you can just omit the scope tag:

<dependency>
 <groupId>com.oracle</groupId>
 <artifactId>ojdbc14</artifactId>
 <version>10.2.0.2</version> 
</dependency>

The difference between both scopes:

  • compile This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
  • provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.