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

2023-12-24

我正在使用 spring boot、hibernate 和 my sql,但出现错误。

org.springframework.beans.factory.UnsatisfiedDependencyException: 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: com.mysql.jdbc.Driver at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE] at com.trial.TrialApplication.main(TrialApplication.java:15) [classes/:na] Caused by: 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: com.mysql.jdbc.Driver at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1135) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] ... 28 common frames omitted Caused by: 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: com.mysql.jdbc.Driver at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] ... 41 common frames omitted Caused by: java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver at org.springframework.util.Assert.state(Assert.java:94) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE] at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:224) ~[spring-boot-autoconfigure-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:176) ~[spring-boot-autoconfigure-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43) ~[spring-boot-autoconfigure-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:83) ~[spring-boot-autoconfigure-2.0.5.RELEASE.jar:2.0.5.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_181] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_181] at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_181] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE] ... 42 common frames omitted

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 https://github.com/dishankgoyal/springsBoot

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


我发现你的项目在我这边运行得很好,你可能会尝试在你这边做一些事情。

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

  2. Remove @ComponentScan()从主班离开@SpringBootApplication there.

    @SpringBootApplication
    public class TrialApplication{    
        public static void main(String[] args) {
            SpringApplication.run(TrialApplication.class, args);
        }       
    }
  1. 通过 project-->rebuild/clean 或运行命令清理你的项目mvn clean install或删除.m2/repository或者重新导入项目或重新启动 IDE/系统可能会有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

spring boot数据库错误数据源“org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration” 的相关文章

随机推荐

  • 回滚 GitHub Desktop(或 Windows 版 Github)中未提交的更改

    我在用着Github 桌面 https desktop github com 以前称为适用于 Windows 的 GitHub https windows github com 并且我对本地文件做了很多更改 事情变得如此混乱 我决定只想将本
  • WordPress 上的 Google Analytics 事件跟踪

    我试图在单击特定菜单项时发送事件 我的头脚本如下
  • BI 设计器多对多关系

    我是 Microsoft Power BI 设计器的新手 注意到了这一点文档 https support powerbi com knowledgebase articles 464155 create and manage relatio
  • 使用霍夫变换、OpenCV 和 python 进行平行线检测

    我需要有关我一直在研究的算法的帮助 我试图检测阈值图像中的所有线条 检测所有线条 然后仅输出平行的线条 阈值图像输出我感兴趣的对象 然后我通过精明的边缘检测器过滤该图像 然后将该边缘图像通过概率霍夫变换 现在 我希望该算法能够检测任何图像中
  • 将 Java byte[] 对象插入 H2 表中,然后再次检索它

    我正在尝试将 Java byte 插入 H2 数据库表中 然后再次检索它 但我没有取得成功 根据这一页 http www h2database com html datatypes html binary type BINARY 数据类型直
  • 无法使用 jdbcStorageHandler 创建 Hive 外部表

    我正在 Amazone EMR 中运行一个小型集群 以便使用 Apache Hive 2 3 5 据我了解 Apache Hive 可以从远程数据库导入数据并让集群运行查询 我正在遵循 Apache Hive Web 文档中提供的示例 ht
  • 遵循 Python/Flask Heroku 教程时出现“foreman start”错误

    遵循所有指示 运行的时候出现这个错误foreman start C Program Files x86 ruby 1 9 3 lib ruby gems 1 9 1 gems foreman 0 47 0 lib fo reman engi
  • 使窗口成为桌面的一部分

    我想创建一个窗口 CreateWindowEx WS EX TOOLWINDOW WS EX LAYERED wc lpszClassName 0 WS POPUP WS VISIBLE WS SYSMENU a part桌面的 我知道这可
  • 2020 年以上,Typescript 在运行时使用类型防护按类型或接口检查对象

    对我来说 大多数时候 需要动态检查来验证获取响应 我在想 对于具有多个道具和附加检查的任何类型的对象 可以使用用户定义的类型保护以通用方式完成此操作 因此可以使用类似的方法 这是一个带有示例对象的示例 但我想要一个没有它的函数 https
  • postgresql 中的慢 OR 语句

    我目前的 postgresql 查询由于 OR 语句而变慢 因此 它显然没有使用索引 到目前为止 重写此查询失败 查询 EXPLAIN ANALYZE SELECT a0 id AS id0 FROM advert a0 INNER JOI
  • 抑制 Xcode 中已弃用的警告

    由于所有 SDK 都在使用 因此能够方便地针对多个 SDK 和平台进行构建 然而 从 3 2 跳到 3 0 甚至偶尔跳到 2 x 我经常收到涉及已更改或被取代的方法的弃用警告 warning UIKeyboardBoundsUserInfo
  • JPA - 仅针对给定查询强制延迟加载

    如何仅针对给定的 NamedQuery 实施延迟加载策略 例如 考虑下面的伪代码 只是为了解释这种情况 我有一个实体 Entity class Xyz int a int b Fetch EAGER Set
  • pandas 数据框 groupby 和 join

    让我们假设有这样的 np random seed 123 df pd DataFrame A foo bar foo bar foo bar foo foo B one one two three two two one three C n
  • NLTK - 获取并简化标签列表

    我正在使用布朗语料库 我想要某种方法来打印所有可能的标签及其名称 而不仅仅是标签缩写 标签也不少 有没有办法 简化 标签呢 我所说的简化是指将两个极其相似的标签合并为一个 然后用另一个标签重新标记合并后的单词 之前以某种方式讨论过 Java
  • 仅 DIV 的两列 CSS 布局

    我正在重新设计当前使用表格进行两列设计的布局 并遇到了一些问题 div div div blah div div div div blah div div blah div div div leftCol margin right 10px
  • 如何使用反射获取泛型类的名称?

    如何使用反射获取泛型类的名称 eg public class SomeGenericClass
  • Android 地理围栏的最大限制?

    我从 Google Play 服务的地理围栏 API 开始 我想我理解了一般概念 但我不知道地理围栏是否有限制 我将地理围栏列表提供给位置客户端 然后由他处理其余的事情 但是我可以将多少个地理围栏传递给位置客户端 我想要多少就多少 每个设备
  • 直接在 .htaccess 文件内生成随机数

    目前我正在添加一个随机数到我的结束Ajax通过 Javascript 或 PHP 的 URL 我想知道我是否可以在我的内心做同样的事情 htaccess文件 当我使用 mod rewrite 重写它们时 有什么办法可以制作一个随机数 or
  • ng-click刷新页面而不是提交

    您好 我有一个有角度的 Web 表单 它接受用户的输入并插入到数据库中 我正在使用 jersey jackson Rest Web 服务和 hibernate 但是当我尝试提交表单时 上一页有指向当前页面的超链接刷新页面并再次重新加载当前页
  • spring boot数据库错误数据源“org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration”

    我正在使用 spring boot hibernate 和 my sql 但出现错误 org springframework beans factory UnsatisfiedDependencyException Error creati