在 docker 上部署时创建 mongock bean 时出错

问题描述

我正在使用 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]

查看完整日志here

这是 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 方法是否不正确。

有人请帮我

解决方法

如本 Github issue 中所述,问题已通过升级到 4.3.7 版解决。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...