当前位置: 首页 > 知识库问答 >
问题:

从spring工具套件连接到数据库时出错

袁增
2023-03-14

创建名为“org.springframework.boot.autocconfigure.orm.jpa.Hibernatejpaconfiguration”的bean时出错:通过构造函数参数0表示的依赖项不满足;嵌套异常为org.springframework.beans.factory.beanCreationException:创建类路径资源[org/springframework/boot/autoconfigure/jdbc/datasourceConfiguration$hikari.class]中定义的名为“data source”的bean时出错:通过工厂方法实例化bean失败;嵌套异常为org.springframework.beans.beanInstantiationException:无法实例化[com.zaxxer.hikari.hikaridataSource]:工厂方法“data source”引发异常;嵌套异常为java.lang.IllegalStateException:无法加载驱动程序类:Oracle.jdbc.driver.OracleDriver

<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>

控制器类

@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);

    }
}

模型类

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

共有1个答案

云远
2023-03-14

正在添加依赖项:

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

和正确的Hibernate方言-org.hibernate.dialt.OracleDialect应该可以工作。

 类似资料:
  • 我是php的初学者,对于一个项目,我想把我和数据库连接起来,但问题是: 我需要4个变量: 当我这样做时: 有两个错误: 警告:mysqli::mysqli():php_network_getaddress:getaddrinfo失败:第21行/home/ubuntu/workspace/index.php中的名称或服务未知 而且 警告:mysqli::mysqli():(HY000/2002):p

  • 查询数据库时出错。原因:org.springframework.JDBC.canNotgetJDBCConnectionException:未能获得JDBC连接;嵌套异常是java.sql.sqlexception:对文件“d:companydbprodatafile.fdb”进行“createFile(open)”操作时发生I/O错误;试图打开文件时出错;[SQLSTATE:08001,ISC错

  • 我有一个数据库。当我尝试使用库UCanAccess连接到它时: 连接时获取: 此类错误: 如果我只导出所需的表并连接到它,没有错误。但是我需要使用完整的数据库。 编辑 我删除了对DB中不存在文件的引用,但错误仍然存在:

  • 我目前正试图找到一个替代我的android应用程序后端。目前,我使用php servlets查询Mysql数据库。数据库(Mysql)托管在我学院的一台计算机上,所以我不能更改任何配置,因为我不是管理员。我只能编辑自己的表。 我试图使用以下代码创建一个java RESTful服务器:

  • 问题 当我启动超过11个Spring Boot项目并行时,我无法从数据库中检索数据。我只得到空白的JSON响应。但是如果我只启动了不到11个项目,那么在那个时候,我就能够得到微服务的结果。当我从12号发球开始的时候有问题。 但这并没有解决我的问题。并且在我的中为连接池添加了其他行, 即使这样也不能解决我的问题。仍然,我只能启动最多12个Spring引导项目一次。 在pom.xml中添加了以下内容,

  • 有人能帮帮我吗?在网上找不到有关此问题的任何内容。