1

I am in the process of migrate a spring boot application from 2.2.2 to 2.2.3. I also upgrade mongock to 4.1.16 as the version 2.0.2 used so far is not compatible anymore.

I have this changelog which works fine in 2.0.2 but not in 4.1.16 :

    @ChangeSet(order = "001", id = "initDatabaseParametre", author = "xxxxx")
    public void initDatabaseParametre(ParametreManager parametreManager, ObjectMapper mapper) throws IOException 
        // someting
    }

With 4.1.16 I have this exception because ObjectMapper is not an interface (com.fasterxml.jackson.databind.ObjectMapper) :

io.changock.migration.api.exception.ChangockException: Error in method[ChangelogInitDatabase.initDatabaseParametre] : Parameter of type [ObjectMapper] must be an interface
        at io.changock.runner.core.MigrationExecutor.processExceptionOnChangeSetExecution(MigrationExecutor.java:179)
        at io.changock.runner.core.MigrationExecutor.processSingleChangeSet(MigrationExecutor.java:97)
        at io.changock.runner.core.MigrationExecutor.lambda$processSingleChangeLog$2(MigrationExecutor.java:89)
        at io.changock.runner.core.MigrationExecutor.executeInTransactionIfStrategyOrUsualIfNot(MigrationExecutor.java:75)
        at io.changock.runner.core.MigrationExecutor.processSingleChangeLog(MigrationExecutor.java:89)
        at io.changock.runner.core.MigrationExecutor.lambda$processAllChangeLogs$1(MigrationExecutor.java:83)
        at io.changock.runner.core.MigrationExecutor.executeInTransactionIfStrategyOrUsualIfNot(MigrationExecutor.java:75)
        at io.changock.runner.core.MigrationExecutor.processAllChangeLogs(MigrationExecutor.java:83)
        at io.changock.runner.core.MigrationExecutor.lambda$executeMigration$0(MigrationExecutor.java:64)
        at com.github.cloudyrock.mongock.driver.mongodb.springdata.v3.SpringDataMongo3Driver.executeInTransaction(SpringDataMongo3Driver.java:108)
        at io.changock.runner.core.MigrationExecutor.executeInTransactionIfStrategyOrUsualIfNot(MigrationExecutor.java:73)
        at io.changock.runner.core.MigrationExecutor.executeMigration(MigrationExecutor.java:64)
        at io.changock.runner.spring.v5.core.SpringMigrationExecutor.executeMigration(SpringMigrationExecutor.java:38)
        at io.changock.runner.core.ChangockBase.execute(ChangockBase.java:44)
        at io.changock.runner.spring.v5.ChangockSpringBuilderBase$ChangockSpringApplicationRunner.run(ChangockSpringBuilderBase.java:110)
        at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:786)
        at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:776)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
        at com.myproject.MyApplication.main(MyApplication.java:23)
Caused by: io.changock.migration.api.exception.ChangockException: Parameter of type [ObjectMapper] must be an interface
        at io.changock.runner.core.DependencyManagerWithContext.getDependency(DependencyManagerWithContext.java:42)
        at io.changock.runner.core.MigrationExecutor.getParameter(MigrationExecutor.java:165)
        at io.changock.runner.core.MigrationExecutor.executeChangeSetMethod(MigrationExecutor.java:155)
        at io.changock.runner.core.MigrationExecutor.executeAndLogChangeSet(MigrationExecutor.java:111)
        at io.changock.runner.spring.v5.core.SpringMigrationExecutor.executeAndLogChangeSet(SpringMigrationExecutor.java:44)
        at io.changock.runner.core.MigrationExecutor.processSingleChangeSet(MigrationExecutor.java:95)
        ... 19 common frames omitted

I need ObjectMapper in my changelogs because my migration process reads json files.

Olivier
  • 65
  • 3

1 Answers1

2

As you can see in the Using custom beans in changeSet methods section, in the Mongock's documentation, the custom beans you use in your changeSet must be interfaces.

Here there is some explanation.

However, you can tell Mongock you don't want that. The less intrusive mechanism is by adding the annotation @NonLockGuarded to you changeSet parameter, as explained in this section.

The down side of that approach is that you need to add the annotation every time you use that bean in all your changeSets. Maybe a more convenient way, but also more intrusive, is by adding the same annotation to your bean's type, in this case ObjectMapper, as explained in this section.

As I assume it's the jackson's ObjectMapper, instead all of this, you can take the SpringContext as parameter and get ObjectMapper bean from it, but it's not ideal, for obvious reasons(this applies to any kind of bean)

Mongock team
  • 1,188
  • 5
  • 9