Reputation: 69
I am trying to connect to MySQL dB using spring boot. As Spring boot requires very less configuration I am not getting where I am going wrong. My Code Structure is Like, I have main class which starts application, A model Customer class, A web Controller class. A customer Repository Interface to implement CRUD operations.
public interface CustomerRepository extends CrudRepository<Customer, Long>
{
List<Customer> findByLastName(String lastName);
}
application.properties file
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.
Upvotes: 1
Views: 6401
Reputation: 69
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. I just added version property in dependency of MySQL and it get connected.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
Upvotes: 4