2

Below is my application.properties file

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@abc:1512:dbq
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update

Below is my POM.xml

      <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/>
      </parent>
    <dependencies>


            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency> 

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>

             <dependency>
                <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-starter-jdbc</artifactId>
            </dependency> 

            <dependency>
                <groupId>org.codehaus.jettison</groupId>
                <artifactId>jettison</artifactId>
                <version>1.4.0</version>
            </dependency>

      </dependencies>

I have created new maven + Spring boot with latest version project using eclipse. But getting below error when try to autowired JdbcTemplate. I have share my properties file and pom.xml above.

    Error::
    org.springframework.beans.factory.UnsatisfiedDependencyException: 
    Error creating bean with name 'asurintApp': Unsatisfied dependency 
    expressed through field 'jdbcTemplate'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration$JdbcTemplateConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.Ill`enter code here`egalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver
halfer
  • 19,824
  • 17
  • 99
  • 186
Rahil
  • 71
  • 2
  • 7
  • If you use spring-boot then it is better to use JPA. – Sanjay Jul 29 '18 at 05:54
  • when I add dependency" org.springframework spring-jdbc 4.1.4.RELEASE " instead of "spring-boot-starter-jdbc" then getting Consider defining a bean of type 'org.springframework.jdbc.core.JdbcTemplate' in your configuration. – Rahil Jul 29 '18 at 05:55
  • `Cannot load driver class: oracle.jdbc.driver.OracleDriver` -> you are missing `ojdbc` dependency – Ori Marko Jul 29 '18 at 05:58
  • Added : com.oracle ojdbc7 12.1.0 BUT getting same error – Rahil Jul 29 '18 at 06:03
  • oracle ojdbc6 11.2.0.3 Try adding this dependency – Jabir Jul 29 '18 at 06:56

2 Answers2

2

You are missing the jdbc driver for the Oracle database.

Unfortunately due the binary license there is no public repository with the Oracle Driver JAR. Try to add it to you pom following this answer.

Seakayone
  • 610
  • 5
  • 11
  • Thank you, it's working for me. But why external jar required for jdbctemplate? – Rahil Jul 30 '18 at 16:15
  • The jdbctemplate actually would allow you to access a range of realtional databases using the same interface., but for each different database you would need a new driver. The oracle drivers are in the external jar and will be used by jdbc. Unfortunately these drivers are not open source and thus due to the licence it is necessary to jump through some hoops. – Seakayone Sep 21 '18 at 15:12
0

I add this to show another way to store jar in spring-boot app. This way if new developer pull this application he/she will not need to follw this way.

Make a dir lib inside src : src/lib/

then put your ojdbc-{versio}.jar in lib folder and then add this dependency in gradle:

compile files('src/lib/ojdbc8-{version}.jar')

for maven add this dependency:

<dependency>
groupId ...
artifactId ...
version ...
<scope>system</scope
<systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
GolamMazid Sajib
  • 8,698
  • 6
  • 21
  • 39