Tuesday, July 9, 2013

Camel Route: Quering Oracle DB


camel-context.xml





 
  
   
   
    Select * from ACCOUNT
   
   
   
  
 

 
  
  
  
  
 

 



pom.xml



  
  
   org.apache.camel
   camel-core
   2.10.0.redhat-60024
  

  
   org.apache.camel
   camel-spring
   2.10.0.redhat-60024
  

  
   org.apache.camel
   camel-jdbc
   2.10.0.redhat-60024
  

  
    org.springframework
    spring-jdbc
    3.1.0.RELEASE
   

   
    com.oracle
    ojdbc6
   11.2.0
   

  


Following dependency issued were encountered when implementing the above.

java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource 

Adding spring-jdbc jar was the solution, but the question was which version.


org.springframework
spring-jdbc
x.x.x


Tried 1.2.9, 2.0.1, 2.5.6. All gave the following error.

[ERROR] Failed to execute goal org.apache.camel:camel-maven-plugin:2.10.0.redhat-60024:run (default-cli) on project poc-database: null: MojoExecutionException: org/springframework/core/env/EnvironmentCapable: org.springframework.core.env.EnvironmentCapable -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

Running with -e switch revealed the following error.


Caused by: java.lang.NoClassDefFoundError: org/springframework/core/env/EnvironmentCapable

This class was found in 3.x versions of spring-jdbc. Tried with 3.1.0.RELEASE, and it gave the following error.

[ERROR] Failed to execute goal org.apache.camel:camel-maven-plugin:2.10.0.redhat-60024:run (default-cli) on project poc-database: null: MojoExecutionException: InvocationTargetException: Error creating bean with name 'dataSource' defined in URL [file:/home/kl40306/SAM6/Fuse_POC/workspace/poc-database/src/main/resources/META-INF/spring/DatabaseSample.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driverClass' of bean class [org.springframework.jdbc.datasource.DriverManagerDataSource]: Bean property 'driverClass' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? -> [Help 1]
[ERROR]

The reason is the attribute which was "driverClass" is now "driverClassName" in DriverManagerDataSource.

After fixing the above, following error came up.

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]

Needed to add Oracle maven dependency.


   com.oracle
   ojdbc6
   11.2.0
  

This is not downloaded automatically from maven repositories. Need to install manually.

Download the jar and run

mvn install:install-file -Dfile=/path_to_jar/ojdbc.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar


No comments:

Post a Comment