I have a problem with proper configure mongock for my project.
I have added to pom.xml dependencies:
<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>
I have added annotation on ApplicationClass: @EnableMongock
In application.yml I have added configuration:
mongock:
migration-scan-package:
- com.test.project.config.dbmigrations
enabled: true
Documentation says that this setup should be enough, but when I run app I have got error:
***************************
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.
Do you know how to fix it? Thanks in advance.
3
Answers
You can try by making a setup bean.
Depending on the version of Spring Boot you are using, this likely has different causes:
When using Spring Boot 3.x.x you need to use
instead of
mongock-springboot
as stated in GitHub issue #589.If using Spring Boot 2.x.x or above change does not work, for some reason the Bean is not auto-detected.
Defining the Bean manually should solve/workaround this:
Either use the Builder approach instead of the
@EnableMongock
Annotation.You can choose between the ApplicationRunner or the InitializingBeanRunner.
An example for such a Runner can be found in the Mongock-examples repo.
Alternatively you can only define the ConnectionDriver Bean while keeping the Annotation approach with something like this:
If you are using spring 3.x.x version, the dependencies mentioned in documentations are not proper. Use dependencies like below in order to make autoconfiguration to work:
Post this, your configuration in
application.yml
will work