我的项目中有以下配置,但由于某些原因,更改日志从未执行过。
你知道我错过了什么吗?
我可以成功地使用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();Changelog类:
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
}
}发布于 2020-09-02 18:46:46
也许你是在跟踪quick start in Mongock's documentation。多亏了这张票,我们在文档中发现了一个bug。使用以下代码构建runner之后:
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();https://stackoverflow.com/questions/63636993
复制相似问题