1

我正在使用 Mongck 在我的 Spring Boot 应用程序中迁移数据。Spring Boot 应用程序在本地完美运行。但是在docker上运行时,出现如下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongockInitializingBeanRunner' defined in class path resource [vn/vnpt/icode/svc/config/config/MongockConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/mongodb/MongoDatabaseFactory

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.2.RELEASE.jar!/:5.2.2.RELEASE]

在此处查看完整日志

这是 build.gradle 文件中的依赖项:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-cache'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'javax.xml.bind:jaxb-api'
    
    implementation 'com.github.cloudyrock.mongock:mongock-bom:4.3.7'
    implementation 'com.github.cloudyrock.mongock:mongodb-springdata-v3-driver:4.3.7'
    implementation 'com.github.cloudyrock.mongock:mongock-spring-v5:4.3.7'


    
    
    implementation 'com.hazelcast:hazelcast-kubernetes:2.0'
    implementation 'com.hazelcast:hazelcast-spring'
    implementation 'org.springframework.cloud:spring-cloud-starter-stream-kafka:3.0.1.RELEASE'
    
//    implementation 'org.apache.poi:poi-ooxml:4.1.1'
    implementation 'org.apache.commons:commons-collections4:4.1'
    implementation 'com.google.code.gson:gson'
    implementation 'org.json:json:20201115'
    
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

以及 MongockConfig 类的内容:

    @Bean
    public MongockSpring5.MongockInitializingBeanRunner mongockInitializingBeanRunner(ApplicationContext springContext, MongoTemplate mongoTemplate) {
        boolean migrationsEnabled = mongoEnabled;
        return MongockSpring5.builder()
                .setDriver(SpringDataMongoV3Driver.withDefaultLock(mongoTemplate))
                .addChangeLogsScanPackages(List.of(changeLogsScanPackage))
                .setSpringContext(springContext)
                .setEnabled(migrationsEnabled)
                .buildInitializingBeanRunner();
    }

我不明白为什么它在 docker 上运行时不起作用。是不是我的mongockInitializingBeanRunner方法不对。

有人请帮助我

4

1 回答 1

1

正如此Github 问题中所讨论的,该问题已通过升级到版本 4.3.7 得到解决。

于 2021-03-14T22:30:00.293 回答