0

我的项目中有以下配置,但由于某种原因,从未执行过更改日志。
关于我所缺少的任何想法?

我可以成功使用 mongo 客户端并执行 CRUD 操作,只是 MongockStandalone 不起作用。

pom.xml

<dependency>
    <groupId>com.github.cloudyrock.mongock</groupId>
    <artifactId>mongock-standalone</artifactId>
    <version>4.1.14</version>
</dependency>
<dependency>
    <groupId>com.github.cloudyrock.mongock</groupId>
    <artifactId>mongodb-v3-driver</artifactId>
    <version>4.1.14</version>
</dependency>
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>3.11.0</version>
</dependency>

主类中的驱动代码:

MongockStandalone.builder()
                 .setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
                 .addChangeLogsScanPackage("co.my.test.persistence.changelog")
                 .buildRunner();

变更日志类:

package co.my.test.persistence.changelog;

//imports

@ChangeLog(order = "001")
public class Changelog001 {

    @ChangeSet(order = "001", id = "test", author = "Igor Flakiewicz")
    public void test() {
        // this method is never executed, the sout doesn't occur and breakpoints are not reached
        System.out.println("PLEASE WORK!");
        // migration code
    }

}
4

1 回答 1

3

可能您正在关注Mongock 文档中的快速入门。多亏了这张票,我们在文档中发现了一个错误。使用以下代码构建运行器后:

MongockStandalone.builder()
             .setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
             .addChangeLogsScanPackage("co.my.test.persistence.changelog")
             .buildRunner();

您需要执行该方法execute()

因此,您应该使用的正确代码类似于:

MongockStandalone.builder()
             .setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
             .addChangeLogsScanPackage("co.my.test.persistence.changelog")
             .buildRunner()
             .execute();
于 2020-09-02T10:46:46.127 回答