mongodb 在io.mongock.runner.springboot.config中找不到方法getBuilder,MongockContext需要类型为“ConnectionDriver”的Bean

cclgggtu  于 2023-02-07  发布在  Go
关注(0)|答案(1)|浏览(109)

我有一个问题,正确配置mongock为我的项目。
我添加了pom.xml依赖项:

<dependencies>
    <dependency>
        <groupId>io.mongock</groupId>
        <artifactId>mongock-springboot</artifactId>
        <version>5.2.2</version>
    </dependency>
    <dependency>
        <groupId>io.mongock</groupId>
        <artifactId>mongodb-springdata-v3-driver</artifactId>
        <version>5.2.2</version>
    </dependency>
    ...
  </dependencies>
  <dependencyManagement>
     <dependencies>
        <dependency>
            <groupId>io.mongock</groupId>
            <artifactId>mongock-driver-mongodb-bom</artifactId>
            <version>5.2.2</version>
            <type>pom</type>
        </dependency>
        ...
    </dependencies>
</dependencyManagement>

我在ApplicationClass上添加了注解:@使能蒙哥克
在application.yml中,我添加了配置:

mongock:
  migration-scan-package:
    - com.test.project.config.dbmigrations
  enabled: true

文档中说这个设置应该足够了,但是当我运行应用程序时,我得到了错误:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method getBuilder in io.mongock.runner.springboot.config.MongockContext required a bean of type 'io.mongock.driver.api.driver.ConnectionDriver' that could not be found.

Action:

Consider defining a bean of type 'io.mongock.driver.api.driver.ConnectionDriver' in your configuration.

你知道怎么修吗?先谢了。

nfeuvbwi

nfeuvbwi1#

您可以尝试创建一个设置bean。

@Bean
    public MongockApplicationRunner mongockApplicationRunner(
            ApplicationContext springContext,
            MongoTemplate mongoTemplate) {
        return MongockSpringboot.builder()
                .setDriver(SpringDataMongoV3Driver.withDefaultLock(mongoTemplate))
                .addMigrationScanPackage("your_changeLog_package_path")
                .setSpringContext(springContext)
                .buildApplicationRunner();
    }

相关问题