Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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!

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda