1

Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': 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.IllegalStateException: Cannot load driver class: oracle.jdbc.driver.OracleDriver

pom.xml file https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.6.RELEASE</version>
</parent>
<groupId>com.Projectdashboardtool</groupId>
<artifactId>Project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Project</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <!-- <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency> -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <!-- <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
    </dependency> -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc8</artifactId>
        <version>12.1.0</version>      
    </dependency> 

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Controller class

@RestController
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectRepository projectRepository;

    @GetMapping
    public List<Project> list(){
        //List<Project> project=new ArrayList<>();
        return projectRepository.findAll();
    }

    @PostMapping
    @ResponseStatus(HttpStatus.OK)
    public void create(@RequestBody Project project) {
        projectRepository.save(project);

    }

    @GetMapping("/{id}")
    public Project get(@PathVariable("id") long id) {
        return projectRepository.getOne(id);

    }
}

Model class

package com.Projectdashboardtool.Project.Model;

import java.sql.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@JsonIgnoreProperties({"hiberanateLazyInitializer", "handler"})
public class Project {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    private String dg_number;
    private String project;
    private String release_level;
    private String release_area;
    private String release_number;

    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="dd-MM-yyyy")
    private Date planned_release_date;
    private Date release_date;

    public String getDg_number() {
        return dg_number;
    }
    public void setDg_number(String dg_number) {
        this.dg_number = dg_number;
    }
    public String getProject() {
        return project;
    }
    public void setProject(String project) {
        this.project = project;
    }
    public String getRelease_level() {
        return release_level;
    }
    public void setRelease_level(String release_level) {
        this.release_level = release_level;
    }
    public String getRelease_area() {
        return release_area;
    }
    public void setRelease_area(String release_area) {
        this.release_area = release_area;
    }
    public String getRelease_number() {
        return release_number;
    }
    public void setRelease_number(String release_number) {
        this.release_number = release_number;
    }
    public Date getPlanned_release_date() {
        return planned_release_date;
    }
    public void setPlanned_release_date(Date planned_release_date) {
        this.planned_release_date = planned_release_date;
    }
    public Date getRelease_date() {
        return release_date;
    }
    public void setRelease_date(Date release_date) {
        this.release_date = release_date;
    }
    public String getRelease_type() {
        return release_type;
    }
    public void setRelease_type(String release_type) {
        this.release_type = release_type;
    }
    private String release_type;

    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    @Override
    public String toString() {
        return "Project [id=" + id + ", dg_number=" + dg_number + ", project=" + project + ", release_level="
                + release_level + ", release_area=" + release_area + ", release_number=" + release_number
                + ", planned_release_date=" + planned_release_date + ", release_date=" + release_date
                + ", release_type=" + release_type + "]";
    }

}

application.properties file
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.SQLServer2012Dialect
spring.datasource.url=jdbc:oracle:thin:@//hostname/servicename
spring.datasource.username=username
spring.datasource.password=password
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
5
  • Could ypu please show your data source bean class Commented May 7, 2020 at 5:47
  • @GauravDhiman : is the updated data which you asked? Commented May 7, 2020 at 6:03
  • Please provide some additional information to your problem. Like the comments show, there is still room for improvement to your question. Commented May 7, 2020 at 7:12
  • Have you created a data source bean? If yes, please share that class, otherwise share your data source properties you have declared Commented May 7, 2020 at 7:16
  • @GauravDhiman: apart from this classes i have mail class and one repository. I am trying application newly. If i miss something pls guide me. Commented May 7, 2020 at 9:48

3 Answers 3

1

Adding dependency :

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>12.1.0</version>      
</dependency>

And correct hibernate dialect - org.hibernate.dialect.OracleDialect should work.

Sign up to request clarification or add additional context in comments.

Comments

0

I think you are using property file for DB oracle. From your exception i can able to see spring boot failed to load oracle driver. So download ojdbc6.jar from Oracle website or if you install oracle11g in your local system you can find ojdbc in jdbc/lib folder.

add this to your project, On eclipse right click on project --> build path --> add this jar.

So suppose you are using spring boot add this dependency to your pom.xml

<dependency>
 <groupId>com.oracle</groupId>
 <artifactId>ojdbc6</artifactId>
 <version>11.2.0</version>//add letest version
</dependency>

Suppose if your dependency not detected by maven follow the below steps:-

Run this command

mvn install:install-file - Dfile=C:\Users\user\.m2\repository\com\oracle\ojdbc6\11.2.0\ojdbc6.jar -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

Then You can Use this.

7 Comments

I have oracle 18.3 version and using ojdbc8 jar and placed in build path
Hi Can you share your DB config
spring.jpa.hibernate.ddl-auto=update spring.jpa.database-platform=org.hibernate.dialect.SQLServer2012Dialect spring.datasource.url=jdbc:oracle:thin:@//hostname/servicename spring.datasource.username=username spring.datasource.password=password spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
Your Hibernate dialect property should be, spring.jpa.database-platform = org.hibernate.dialect.OracleDialect
Thank you Thiru, after changing to OracleDriver i could connect
|
0

Oracle JDBC drivers are available on Central Maven. Check out this blog. You can add this GAV for 18.3 JDBC driver.

<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>18.3.0.0</version>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.