springh2驱动程序问题

n9vozmp4  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(205)

我试图运行一个crud应用程序,但我得到了错误
2020-12-22 09:48:40.787警告83274---[main]configservletwebserverapplicationcontext:上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.unsatifiedDependencyException:创建名为“org.springframework.boot.autoconfigure.orm.jpa.hibernatejpaconfiguration”的bean时出错:通过构造函数参数0表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.beancreationexception:创建名为'datasource'的bean时出错,该bean在类路径资源[org/springframework/boot/autoconfigure/jdbc/datasourceconfiguration$hikari.class]中定义:通过工厂方法示例化bean失败;嵌套异常为org.springframework.beans.beaninstantiationexception:未能示例化[com.zaxxer.hikari.hikaridatasource]:工厂方法“datasource”引发异常;嵌套异常为java.lang.illegalstateexception:无法加载驱动程序类:org.h2.driver
我无法连接h2。它在application.properties中以红色键入,如下所示。

这也是我完整的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>API</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>API</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>11</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </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-web</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>2.0.1.Final</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

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

hyrbngr71#

您不需要指定 driverClassName 或者 database-platform ,在添加h2依赖项之后,spring将使用默认值。你需要这个吗 mysql-connector-java 在依赖关系中?

相关问题