Error connecting spring boot to mysql

Asked

Viewed 938 times

0

The error in spring boot is :

Error Starting Applicationcontext. To display the conditions report re-run your application with 'debug' enabled. 2018-07-14 16:11:53.259 ERROR 13188 --- [ restartedMain] o.s.boot.Springapplication : Application run failed

org.springframework.Beans.factory.Beancreationexception: Error Creating bean with name 'flywayInitializer' defined in path class Resource [org/springframework/boot/autoconfigure/flyway/Flywayautoconfiguration$Flywayconfiguration.class]: Invocation of init method failed; nested Exception is org.flywaydb.core.api.Flywayexception: Validate failed: Detected failed Migration to version 01 (creates and registers categories)

org.springframework.Beans.factory.Beancreationexception: Error Creating bean with name 'flywayInitializer' defined in path class Resource [org/springframework/boot/autoconfigure/flyway/Flywayautoconfiguration$Flywayconfiguration.class]: Invocation of init method failed; nested Exception is org.flywaydb.core.api.Flywayexception: Validate failed: Detected failed Migration to version 01 (creates and registers categories)

Code of aplications.proprietes

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/banco
spring.datasource.username=root
spring.datasource.password=danilo20

Code of the database

CREATE DATABASE banco;
USE banco;
CREATE TABLE categoria (
id BIGINT(20) PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL
);

INSERT INTO categoria(name) values("Lazer");
INSERT INTO categoria(name) values("Alimentação");
INSERT INTO categoria(name) values("SuperMercado");
INSERT INTO categoria(name) values("Academia");

I even gave a drop table , but it still doesn’t work.

1 answer

0


According to the error, you may be having problems with flyway, however, there are some variants that may be causing this problem, it is up to you to analyze and verify which would be the most relevant to solve your problem.

1 - You need to add this information in Aplication.properties :

spring.jpa.database-platform=org.mariadb.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

NOTE: This information is for Mariadb .

2 - If the error persists, there are some versions of Mysql that require the url to be written this way:

spring.datasource.url=jdbc:mysql://localhost/nameBase?createDatabaseIfNotExist=true&useSSL=false

3 - Don’t forget that flyway should follow the following rule:

3.1. Migrations must be in the Resources/db/Migration folder

3.2. And the names must follow the pattern of V01__cria_e_insere_categoria.sql

To check your flyway migrations, you can use the following command:

   mvn flyway:info 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.