[英]Unable to connect MySql Using Spring Boot JPA
I am trying to connect to MySQL dB using spring boot. 我正在尝试使用Spring Boot连接到MySQL dB。 As Spring boot requires very less configuration I am not getting where I am going wrong.
由于Spring Boot所需的配置非常少,所以我不会出错。 My Code Structure is Like, I have main class which starts application, A model Customer class, A web Controller class.
我的代码结构就像,我有启动应用程序的主类,一个模型Customer类,一个Web Controller类。 A customer Repository Interface to implement CRUD operations.
客户存储库接口,用于实现CRUD操作。
public interface CustomerRepository extends CrudRepository<Customer, Long>
{
List<Customer> findByLastName(String lastName);
}
application.properties file 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
I am getting errors as: 我收到以下错误消息:
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.
It worked. 有效。 Actually I am using spring boot parent version as 1.5.8 which is older and MYSQL with latest version as 8.0.11 which was causing compatibility issue.
实际上,我使用的Spring Boot父版本为1.5.8,这是较旧的版本,而MYSQL的最新版本为8.0.11,这导致了兼容性问题。 I just added version property in dependency of MySQL and it get connected.
我刚刚添加了版本属性,它依赖于MySQL,并且可以连接。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.