我正在尝试运行 mongock 以使用版本控制来处理我的数据库迁移,但是从 mongock 基础架构中得到了一个异常,另外请注意我没有使用 spring-boot 只使用 spring bean 系统,我没有选择使用 spring boot。 ..
Pom 和代码片段:
<dependency>
<groupId>com.github.cloudyrock.mongock</groupId>
<artifactId>mongock-standalone</artifactId>
<version>4.1.19</version>
</dependency>
<dependency>
<groupId>com.github.cloudyrock.mongock</groupId>
<artifactId>mongodb-springdata-v2-driver</artifactId>
<version>4.1.19</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.8.2</version>
</dependency>
代码:
@Configuration
@Import({MongoSelectorContext.class})
public class MongockBeans {
private final MongoSelectorContext mongoSelectorContext;
public MongockBeans(MongoSelectorContext mongoSelectorContext) {
this.mongoSelectorContext = mongoSelectorContext;
}
@Bean
public void updateMongoTemplateSchema() {
MongoTemplate mongoTemplate = mongoSelectorContext.mongoTemplateProvider().getMongoTemplateByDatabaseAlias("test");
MongockStandalone.builder()
.setDriver(SpringDataMongo2Driver.withDefaultLock(mongoTemplate))
.addChangeLogClass(TestChangeLog.class)
.buildRunner().execute();
}
}
Mongo 模板按应有的方式提供 但我收到以下错误,错误是从 mongock 而不是我的变更集引发的,它甚至不执行我的变更集。任何帮助都会有帮助
Exception in thread "main" java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongockBeans': Invocation of init method failed; nested exception is io.changock.migration.api.exception.ChangockException: Error in method[MongockV3LegacyMigrationChangeRunAlwaysLog.mongockSpringLegacyMigration] : Wrong parameter[MongockLegacyMigration] with name: legacy-migration
at com.citi.qi.core.platform.CorePlatformLauncher.start(CorePlatformLauncher.java:39)
at com.citi.quickinsight.evaluation.engine.EngineMain.main(EngineMain.java:35)
...
Caused by: io.changock.migration.api.exception.ChangockException: Error in method[MongockV3LegacyMigrationChangeRunAlwaysLog.mongockSpringLegacyMigration] : Wrong parameter[MongockLegacyMigration] with name: legacy-migration
at io.changock.runner.core.MigrationExecutor.processExceptionOnChangeSetExecution(MigrationExecutor.java:195)
at io.changock.runner.core.MigrationExecutor.processSingleChangeSet(MigrationExecutor.java:102)
at io.changock.runner.core.MigrationExecutor.lambda$processSingleChangeLog$2(MigrationExecutor.java:94)
at io.changock.runner.core.MigrationExecutor.executeInTransactionIfStrategyOrUsualIfNot(MigrationExecutor.java:80)
at io.changock.runner.core.MigrationExecutor.processSingleChangeLog(MigrationExecutor.java:94)
at io.changock.runner.core.MigrationExecutor.lambda$processAllChangeLogs$1(MigrationExecutor.java:88)
at io.changock.runner.core.MigrationExecutor.executeInTransactionIfStrategyOrUsualIfNot(MigrationExecutor.java:80)
at io.changock.runner.core.MigrationExecutor.processAllChangeLogs(MigrationExecutor.java:88)
at io.changock.runner.core.MigrationExecutor.lambda$executeMigration$0(MigrationExecutor.java:69)
at io.changock.runner.core.MigrationExecutor.executeInTransactionIfStrategyOrUsualIfNot(MigrationExecutor.java:80)
at io.changock.runner.core.MigrationExecutor.executeMigration(MigrationExecutor.java:69)
at io.changock.runner.core.ChangockBase.execute(ChangockBase.java:49)
at com.citi.quickinsight.MongockBeans.updateMongoTemplateSchema(MongockBeans.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
... 14 more
Caused by: io.changock.driver.api.common.DependencyInjectionException: Wrong parameter[MongockLegacyMigration] with name: legacy-migration
at io.changock.runner.core.MigrationExecutor.lambda$getParameter$4(MigrationExecutor.java:182)
at java.util.Optional.orElseThrow(Optional.java:290)
at io.changock.runner.core.MigrationExecutor.getParameter(MigrationExecutor.java:182)
at io.changock.runner.core.MigrationExecutor.executeChangeSetMethod(MigrationExecutor.java:171)
at io.changock.runner.core.MigrationExecutor.executeAndLogChangeSet(MigrationExecutor.java:127)
at io.changock.runner.core.MigrationExecutor.processSingleChangeSet(MigrationExecutor.java:100)
... 32 more