【发布时间】: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