0

在我的 Spring-Boot 项目中,我正在尝试为 MongoDb 实现数据库迁移,而我对 MongoDB 和 mongock 还是很陌生。
以下是有关错误的一些详细信息以及到目前为止我所做的事情:

  1. 我的 pom 具有以下依赖项:

       <artifactId>mongock-spring-v5</artifactId>
       <artifactId>mongodb-springdata-v3-driver</artifactId>
       <artifactId>mongock-bom</artifactId>
       <artifactId>testcontainers-bom</artifactId>
    
  2. 我用' @EnableMongock'注释了我的SpringBoot类

  3. 创建了一个 DatabaseChangeLog 类并使用 '@ChangeLog(order = "001")' 进行了注释。在这个类中,我创建了 ' @ChangeSet(order = "001", id = "00.00.00.01", author = "farzain pathan")' 并将少量数据插入 DB。

  4. 在“application.properties”文件中添加了以下行

    mongock.change-logs-scan-package=com.product.target.config

现在,当我构建项目“mvn clean install”时,出现以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongockBuilder' defined in class path resource [com/github/cloudyrock/spring/v5/MongockSpringDataV3CoreContext.class]: Bean instantiation via factory method failed; nested excep
tion is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.spring.v5.MongockSpring5$Builder]: Factory method 'mongockBuilder' threw exception; nested exception is java.lang.NullPointerException: Cannot invoke "java.ut
il.List.iterator()" because "changeLogsScanPackage" is null
        at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658) ~[na:na]
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:349) ~[junit-jupiter-engine-5.7.0.jar:5.7.0]
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$instantiateAndPostProcessTestInstance$4(ClassBasedTestDescriptor.java:270) ~[junit-jupiter-engine-5.7.0.jar:5.7.0]
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.7.0.jar:1.7.0]
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:269) ~[junit-jupiter-engine-5.7.0.jar:5.7.0]
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$2(ClassBasedTestDescriptor.java:259) ~[junit-jupiter-engine-5.7.0.jar:5.7.0]
        at java.base/java.util.Optional.orElseGet(Optional.java:362) ~[na:na]
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$3(ClassBasedTestDescriptor.java:258) ~[junit-jupiter-engine-5.7.0.jar:5.7.0]
        at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31) ~[junit-jupiter-engine-5.7.0.jar:5.7.0]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:101) ~[junit-jupiter-engine-5.7.0.jar:5.7.0]
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.7.0.jar:1.7.0]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:100) ~[junit-jupiter-engine-5.7.0.jar:5.7.0]
        at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:65) ~[junit-jupiter-engine-5.7.0.jar:5.7.0]
        at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$1(NodeTestTask.java:111) ~[junit-platform-engine-1.7.0.jar:1.7.0]
        at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) ~[junit-platform-engine-1.7.0.jar:1.7.0]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongockBuilder' defined in class path resource [com/github/cloudyrock/spring/v5/MongockSpringDataV3CoreContext.class]: Bean instantiation via factory method failed; n
ested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.spring.v5.MongockSpring5$Builder]: Factory method 'mongockBuilder' threw exception; nested exception is java.lang.NullPointerException: Cannot invo
ke "java.util.List.iterator()" because "changeLogsScanPackage" is null
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:923) ~[spring-context-5.3.3.jar:5.3.3]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:588) ~[spring-context-5.3.3.jar:5.3.3]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.2.jar:2.4.2]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.2.jar:2.4.2]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.2.jar:2.4.2]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.2.jar:2.4.2]
        at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:123) ~[spring-boot-test-2.4.2.jar:2.4.2]
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) ~[spring-test-5.3.3.jar:5.3.3]
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-5.3.3.jar:5.3.3]
        ... 69 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.cloudyrock.spring.v5.MongockSpring5$Builder]: Factory method 'mongockBuilder' threw exception; nested exception is java.lang.NullPointerException: Cannot invoke "java
.util.List.iterator()" because "changeLogsScanPackage" is null
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.3.jar:5.3.3]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.3.jar:5.3.3]
        ... 88 common frames omitted
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "changeLogsScanPackage" is null
        at io.changock.runner.core.builder.RunnerBuilderBase.addScanItemsFromConfig(RunnerBuilderBase.java:140) ~[changock-runner-core-1.1.11.jar:na]
        at io.changock.runner.core.builder.RunnerBuilderBase.setConfig(RunnerBuilderBase.java:125) ~[changock-runner-core-1.1.11.jar:na]
        at io.changock.runner.spring.v5.ChangockSpringBuilderBase.setConfig(ChangockSpringBuilderBase.java:56) ~[changock-spring-v5-runner-1.1.11.jar:na]
        at io.changock.runner.spring.v5.ChangockSpringBuilderBase.setConfig(ChangockSpringBuilderBase.java:30) ~[changock-spring-v5-runner-1.1.11.jar:na]
        at com.github.cloudyrock.spring.v5.MongockSpringDataCoreContextBase.mongockBuilder(MongockSpringDataCoreContextBase.java:15) ~[mongock-spring-v5-4.1.19.jar:na]
        at com.github.cloudyrock.spring.v5.MongockSpringDataV3CoreContext.mongockBuilder(MongockSpringDataV3CoreContext.java:42) ~[mongock-spring-v5-4.1.19.jar:na]
        at com.github.cloudyrock.spring.v5.MongockSpringDataV3CoreContext$$EnhancerBySpringCGLIB$$77ad1773.CGLIB$mongockBuilder$1(<generated>) ~[mongock-spring-v5-4.1.19.jar:na]
        at com.github.cloudyrock.spring.v5.MongockSpringDataV3CoreContext$$EnhancerBySpringCGLIB$$77ad1773$$FastClassBySpringCGLIB$$9b166dc9.invoke(<generated>) ~[mongock-spring-v5-4.1.19.jar:na]
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.3.jar:5.3.3]
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.3.jar:5.3.3]
        at com.github.cloudyrock.spring.v5.MongockSpringDataV3CoreContext$$EnhancerBySpringCGLIB$$77ad1773.mongockBuilder(<generated>) ~[mongock-spring-v5-4.1.19.jar:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.3.jar:5.3.3]
        ... 89 common frames omitted

是的,我确实浏览了官方文档,但没有发现任何有用
的东西(跟随 youtube 视频:链接
如果我需要提供更多信息,请告诉我,我真的很挣扎。

4

1 回答 1

0

我需要更多信息来弄清楚发生了什么。

  • 蒙哥克,春季版
  • 代码:至少你的 Spring 应用程序主类和属性文件
  • Pom 文件至少包含 Mongock 依赖项及其导入方式:使用依赖项管理器等。

我至少需要那个。

于 2021-02-16T15:59:46.107 回答