Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
Flyway Migrate Load Constraint Violation with Spring

I've built some back ends with Node/Express and Go, but this is my first time trying to build one with Java/Spring.

I was told Flyway is the best tool for migrations. I got the SQL migrations working to get the schema set up for all my tables, now I'm trying to seed a user table with a Java-based migration.

Now when I call gradle flywayMigrate, I get this error:

loader constraint violation in interface itable initialization: when
resolving method
"db.migration.V2_1__Add_Users.migrate(Lorg/springframework/jdbc/core/JdbcTemplate;)V" 
the class loader (instance of java/net/URLClassLoader) of the current
class, db/migration/V2_1__Add_Users, and the class loader 
(instance of org/gradle/internal/classloader/VisitableURLClassLoader)
for interface
org/flywaydb/core/api/migration/spring/SpringJdbcMigration have
different Class objects for the type
org/springframework/jdbc/core/JdbcTemplate used in the signature

This is what I have in build.gradle:

buildscript {
    ext {
        springBootVersion = '1.5.2.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }

}

plugins {
    id "org.flywaydb.flyway" version "4.1.2"
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'project-report'

flyway {
    url = 'jdbc:mysql://localhost/upshift?serverTimezone=UTC'
    user = 'root'
    locations = ['db.migration']
}

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.flywaydb:flyway-core')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-security')
    compile("org.springframework:spring-jdbc")
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.security:spring-security-test')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

And this is the java class I am trying to migrate with:

package db.migration;

import org.flywaydb.core.api.migration.spring.SpringJdbcMigration;
import org.springframework.jdbc.core.JdbcTemplate;

public class V2_1__Add_Users implements SpringJdbcMigration {
    public void migrate(JdbcTemplate jdbcTemplate) throws Exception {
        jdbcTemplate.execute("INSERT INTO users (email, password) VALUES ('test@test.com', 'test123')");
    }
}

Any idea what might be happening? I've poked around on here and done a fair bit of Googling but haven't found other similar examples. The whole reason I am doing a Java migration is so that I can try to bring in bCrypt to hash the passwords of my seeded users, but it's definitely possible that I'm thinking about this incorrectly. Any insight would be much appreciated!

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I needed to add spring-jdbc to the buildscript dependencies to get this working with Flyway 4.1.2.

Flyway 4.0.3 worked without it.

buildscript {
    ext {
        springBootVersion = '1.5.2.RELEASE'
        springVersion = '4.3.7.RELEASE'
        flywayVersion = '4.1.2'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.flywaydb:flyway-gradle-plugin:${flywayVersion}")
        classpath("org.springframework:spring-jdbc:${springVersion}")
    }

}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'project-report'
apply plugin: 'org.flywaydb.flyway'

flyway {
    url = 'jdbc:mysql://localhost/upshift?serverTimezone=UTC'
    user = 'root'
    password = 'root'
    locations = ['db.migration']
}

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile("org.flywaydb:flyway-core:${flywayVersion}")
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-security')
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.security:spring-security-test')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

I also added an explicit Flyway version to the compile dependencies to ensure the same version would be used for the gradle tasks and at runtime.

compile("org.flywaydb:flyway-core:${flywayVersion}")

I created a working example in this repo.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda