一尘不染

Spring Boot数据库错误数据源“ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration”

spring-boot

我正在使用Spring Boot,Hibernate和My sql,但出现错误。

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration”的bean时出错:通过构造函数参数0表示的不满意依赖关系;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org
/ springframework / boot / autoconfigure / jdbc / DataSourceConfiguration $
Hikari.class]中定义的名称为“ dataSource”的bean时出错:通过工厂方法进行Bean实例化失败;
嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法’dataSource’引发了异常;嵌套异常是java.lang.IllegalStateException:无法在组织上加载驱动程序类:com.mysql.jdbc.Driver。嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法’dataSource’引发了异常;嵌套的异常是java.lang.IllegalStateException:无法在org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590)〜[spring-
beans-5.0。上加载驱动程序类:com.mysql.jdbc.Driver。
9.RELEASE.jar:5.0.9.RELEASE]位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247)〜[spring-
beans-5.0.9.RELEASE.jar:5.0.9
[RELEASE],位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)〜[spring-
beans-5.0.9。818)〜[spring-
beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)〜[spring-
beans-5.0 .9.RELEASE.jar:5.0.9.RELEASE]
…省略了28个共同的框架原因:org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法’dataSource’被抛出例外;
嵌套异常是java.lang.IllegalStateException:无法在org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)〜[spring-
beans-5.0。中加载驱动程序类:com.mysql.jdbc.Driver。
9.RELEASE.jar:5.0.9.RELEASE]位于org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:

pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.bookstore</groupId>
    <artifactId>bookstore</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>bookstore</name>
    <description>Demo project for Spring Boot</description>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>



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

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

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

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

实体类别为

package com.trial.hibernate;

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


@Entity
public class Employee {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    private String name;
    private String phone;

}

属性文件是

server.port=8181
spring.thymeleaf.cache=false
# create and drop tables and sequences, loads import.sql
spring.jpa.hibernate.ddl-auto=create
# database settings
spring.datasource.url=jdbc:mysql://localhost:3306/bookstore?useSSL=false
spring.datasource.username=root
spring.datasource.password=oracle
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true

github仓库链接是https://github.com/dishankgoyal/springsBoot

我怎样才能解决这个问题?


阅读 2564

收藏
2020-05-30

共1个答案

一尘不染

我发现您的项目在最后阶段运行良好,您可能会尝试在最后完成一些工作。

  1. 尝试更改为 spring.datasource.driverClassName=com.mysql.jdbc.Driver

  2. @ComponentScan()从主要班级中删除,然后就离开@SpringBootApplication那里。

    @SpringBootApplication
    public class TrialApplication{    
        public static void main(String[] args) {
            SpringApplication.run(TrialApplication.class, args);
        }       
    }
    
  3. 按项目清理项目->重建/清理或运行命令,mvn clean install或者删除.m2/repository或重新导入项目或重新启动IDE /系统可能会有所帮助。

2020-05-30