在 docker 上部署时创建 mongock bean 时出错
Error creating mongock bean when deploying on docker
我正在使用 Mongck 迁移我的 Spring 启动应用程序中的数据。 Spring 在本地完美启动应用程序 运行。但是在docker上运行ning时,出现如下错误:
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[=11=](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的内容class:
@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 得到解决。
我正在使用 Mongck 迁移我的 Spring 启动应用程序中的数据。 Spring 在本地完美启动应用程序 运行。但是在docker上运行ning时,出现如下错误:
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[=11=](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的内容class:
@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 得到解决。