找不到具有driverClassName = org.gjt.mm.mysql.Driver的已注册驱动程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了找不到具有driverClassName = org.gjt.mm.mysql.Driver的已注册驱动程序相关的知识,希望对你有一定的参考价值。

我正在开发一个项目并使用弹簧。它工作正常,但当我添加一个数据库时,我有一些例外。

WARN com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=org.gjt.mm.mysql.Driver was not found, trying direct instantiation.
ERROR com.zaxxer.hikari.pool.HikariPool        : root - Exception during pool initialization.

java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) ~[mysql-connector-java-5.1.46.jar:5.1.46]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976) ~[mysql-connector-java-5.1.46.jar:5.1.46]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912) ~[mysql-connector-java-5.1.46.jar:5.1.46]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) ~[mysql-connector-java-5.1.46.jar:5.1.46]......

依赖关系:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</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</artifactId>
    </dependency>

    <dependency>
        <groupId>com.detectlanguage</groupId>
        <artifactId>detectlanguage</artifactId>
        <version>1.1.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.9.1</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>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>

application.property:

#Database settings
spring.datasource.url=jdbc:mysql://localhost:3306/mSecond
spring.jpa.hibernate.ddl-auto=update
spring.datasource.name=name
spring.datasource.password=password
spring.datasource.driver-class-name=org.gjt.mm.mysql.Driver

spring.datasource.tomcat.connection-properties=useUnicode=true;characterEncoding=utf-8;
spring.datasource.sql-script-encoding=UTF-8

数据库的地址正确且有效 - 100%

有人可以展示另一种方法,更适合春天的数据库初始化吗?

答案

如果您使用以下行更改属性文件,它应该工作:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root

这个驱动程序类适用于mysql,你需要使用spring.datasource.username=而不是spring.datasource.name=

我希望这可以帮助你

另一答案

不要使用它,因为它已被弃用!

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

请改用它

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root

以上是关于找不到具有driverClassName = org.gjt.mm.mysql.Driver的已注册驱动程序的主要内容,如果未能解决你的问题,请参考以下文章

具有多个字段的嵌套 AND 和 OR 的 CAML 查询

错误 找不到Xcode No such file or directory

生成消息时找不到主题:UNKNOWN_TOPIC_OR_PARTITION

R中读取文件,找不到路径问题 No such file or directory

R中读取文件,找不到路径问题 No such file or directory

Python subprocess.Popen() error (No such file or directory)