Pio*_*otr 5 java mongodb spring-boot mongock
我在为我的项目正确配置 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>
Run Code Online (Sandbox Code Playgroud)
我在ApplicationClass上添加了注释:@EnableMongock
在 application.yml 中我添加了配置:
mongock:
migration-scan-package:
- com.test.project.config.dbmigrations
enabled: true
Run Code Online (Sandbox Code Playgroud)
文档说这个设置应该足够了,但是当我运行应用程序时出现错误:
***************************
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.
Run Code Online (Sandbox Code Playgroud)
你知道如何修复它吗?提前致谢。
小智 5
如果您使用的是 spring 3.xx 版本,则文档中提到的依赖项不正确。使用如下所示的依赖关系以使自动配置正常工作:
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-bom</artifactId>
<version>5.2.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongock-springboot-v3</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>io.mongock</groupId>
<artifactId>mongodb-springdata-v4-driver</artifactId>
<version>5.2.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
发布此内容,您的配置application.yml
将起作用
小智 2
您可以尝试制作一个安装 bean。
@Bean
public MongockApplicationRunner mongockApplicationRunner(
ApplicationContext springContext,
MongoTemplate mongoTemplate) {
return MongockSpringboot.builder()
.setDriver(SpringDataMongoV3Driver.withDefaultLock(mongoTemplate))
.addMigrationScanPackage("your_changeLog_package_path")
.setSpringContext(springContext)
.buildApplicationRunner();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2343 次 |
最近记录: |