【问题标题】:Unable to connect MySql Using Spring Boot JPA无法使用 Spring Boot JPA 连接 MySql
【发布时间】:2018-10-22 01:14:52
【问题描述】:

我正在尝试使用 spring boot 连接到 MySQL dB。由于 Spring Boot 需要的配置非常少,因此我没有找到出错的地方。 我的代码结构就像, 我有启动应用程序的主类, 一个模型客户类, 一个网络控制器类。 用于实现 CRUD 操作的客户存储库接口。

public interface CustomerRepository extends CrudRepository<Customer, Long>
{
     List<Customer> findByLastName(String lastName);
}

application.properties 文件

spring.datasource.url=jdbc:mysql://localhost:3306/testdb?useSSL=false
spring.datasource.username=root
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update

我收到以下错误:

ERROR 7740 --- [           main] o.a.tomcat.jdbc.pool.ConnectionPool      : 
Unable to create initial connections of pool

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could 
not create connection to database server,
and very long error messages.

【问题讨论】:

  • 您是否能够使用相同的凭据从同一服务器进行连接(例如,使用 mysql GUI 实用程序或从 MySQL CLI)?
  • 是的,我可以在 Mysql 工作台以及从命令提示符中使用相同的 ID 和密码连接到数据库。

标签: java mysql spring-boot jpa


【解决方案1】:

成功了。实际上,我使用的 Spring Boot 父版本为 1.5.8,它较旧,而 MYSQL 的最新版本为 8.0.11,这导致了兼容性问题。我刚刚添加了依赖于 MySQL 的 version 属性,它得到了连接。

<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
         <version>8.0.11</version>
</dependency>

【讨论】:

    猜你喜欢
    • 2016-12-02
    • 2017-07-08
    • 2018-01-06
    • 2020-07-12
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    • 2017-08-02
    • 2018-12-09
    相关资源
    最近更新 更多