英文:
Mongock Standalone not executing changelogs
问题
以下是您提供的内容的翻译:
我在项目中有以下配置,但由于某种原因,更改日志永远不会被执行。
对于我漏掉了什么有什么想法吗?
我可以成功地使用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() {
// 此方法永远不会被执行,sout不会发生,断点也不会被触及
System.out.println("请工作!");
// 迁移代码
}
}
英文:
I have the following configuration in my project but for some reason the change-log is never executed.
Any ideas on what I'm missing?
I can successfully use the mongo client and perform CRUD actions, it's just the MongockStandalone that's not working.
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>
Driver code in main class:
MongockStandalone.builder()
.setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
.addChangeLogsScanPackage("co.my.test.persistence.changelog")
.buildRunner();
Changelog class:
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
}
}
答案1
得分: 4
可能你正在按照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();
英文:
Probably you're following the quick start in Mongock's documentation. Thanks to this ticket we have identified a bug in our documentation.
After building the runner with the following code:
MongockStandalone.builder()
.setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
.addChangeLogsScanPackage("co.my.test.persistence.changelog")
.buildRunner();
You need to execute the method execute()
So the correct code you should be using is something like:
MongockStandalone.builder()
.setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
.addChangeLogsScanPackage("co.my.test.persistence.changelog")
.buildRunner()
.execute();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论