java - 无法使用 Spring Boot JPA 连接 MySql

标签 java mysql spring-boot jpa

我正在尝试使用 spring boot 连接到 MySQL dB。由于 Spring boot 需要的配置非常少,所以我没有弄错。 我的代码结构就像, 我有启动应用程序的主类, 一个模型客户类, 一个网络 Controller 类。 用于实现 CRUD 操作的客户存储库接口(interface)。

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

应用程序.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.

最佳答案

成功了。实际上,我使用的 spring boot 父版本为 1.5.8,这是较旧的版本,而 MYSQL 的最新版本为 8.0.11,这导致了兼容性问题。我只是添加了依赖于 MySQL 的版本属性,它就连接上了。

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

关于java - 无法使用 Spring Boot JPA 连接 MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50295389/

相关文章:

java - 使用 AbstractTableModel 从 JTable 中删除或添加行

java - mvn 发布 :prepare in spring boot 时无法将文件提交到 github

java - 使用 Gson 创建特定的 JSON 字符串

java形式继承从 super 构造函数调用错误的方法

Java - 静态变量的副本也是静态的吗?

c# - 无法从 C# 应用程序连接远程服务器 mysql 数据库

mysql - 左外连接的 MAX 条件

c# - MySQL 数据库未显示在数据源中

java - 无法读取application.yml文件

spring-boot - 如何通过单个请求将图像和 JSON 对象发布到后端 Spring Boot