mongock / mongock

Lightweight Java based migration tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transaction Manager not provided error

CiaranMc93 opened this issue · comments

Description

When transactionEnabled: true is provided, I am unable to start my application. Upon removing the configuration, the application starts and performs the migration but I get this log output:

2022-10-13 08:49:18.513 WARN 31740 --- [ main] i.m.r.core.builder.RunnerBuilderBase : Property transaction-enabled not provided. It will become true as default in next versions. Set explicit value to false in case transaction are not desired.
2022-10-13 08:49:18.513 WARN 31740 --- [ main] i.m.r.core.builder.RunnerBuilderBase : Property transaction-enabled not provided and is unknown if driver is transactionable. BY DEFAULT MONGOCK WILL RUN IN NO-TRANSACTION MODE.

Full output below:

2022-10-13 08:49:17.991 INFO 31740 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-10-13 08:49:17.991 INFO 31740 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1358 ms
2022-10-13 08:49:18.152 INFO 31740 --- [ main] org.mongodb.driver.client : MongoClient with metadata {"driver": {"name": "mongo-java-driver|sync|spring-boot", "version": "4.6.0"}, "os": {"type": "Windows", "name": "Windows 10", "architecture": "amd64", "version": "10.0"}, "platform": "Java/Oracle Corporation/11.0.8+10-LTS"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=MongoCredential{mechanism=null, userName='mongoRootAdmin', source='admin', password=, mechanismProperties=}, streamFactoryFactory=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.Jep395RecordCodecProvider@733c464f]}, clusterSettings={hosts=[127.0.0.1:27017], srvServiceName=mongodb, mode=SINGLE, requiredClusterType=UNKNOWN, requiredReplicaSetName='null', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='30000 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, sendBufferSize=0}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, sendBufferSize=0}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=JAVA_LEGACY, serverApi=null, autoEncryptionSettings=null, contextProvider=null}
2022-10-13 08:49:18.183 INFO 31740 --- [127.0.0.1:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:215}] to 127.0.0.1:27017
2022-10-13 08:49:18.183 INFO 31740 --- [127.0.0.1:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:216}] to 127.0.0.1:27017
2022-10-13 08:49:18.185 INFO 31740 --- [127.0.0.1:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=127.0.0.1:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=7, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=39428600, setName='rs-dev', canonicalAddress=devmongo01:27017, hosts=[devmongo01:27017, devmongo03:27017, devmongo02:27017], passives=[], arbiters=[], primary='devmongo01:27017', tagSet=TagSet{[]}, electionId=7fffffff0000000000000013, setVersion=633340, topologyVersion=null, lastWriteDate=Thu Oct 13 08:49:16 BST 2022, lastUpdateTimeNanos=162941657151100}
2022-10-13 08:49:18.457 INFO 31740 --- [ main] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:217}] to 127.0.0.1:27017
2022-10-13 08:49:18.512 INFO 31740 --- [ main] i.m.r.core.builder.RunnerBuilderBase : Mongock runner COMMUNITY version[5.1.6]
2022-10-13 08:49:18.513 INFO 31740 --- [ main] i.m.r.core.builder.RunnerBuilderBase : Running Mongock with NO metadata
2022-10-13 08:49:18.513 WARN 31740 --- [ main] i.m.r.core.builder.RunnerBuilderBase : Property transaction-enabled not provided. It will become true as default in next versions. Set explicit value to false in case transaction are not desired.
2022-10-13 08:49:18.513 WARN 31740 --- [ main] i.m.r.core.builder.RunnerBuilderBase : Property transaction-enabled not provided and is unknown if driver is transactionable. BY DEFAULT MONGOCK WILL RUN IN NO-TRANSACTION MODE.
2022-10-13 08:49:18.553 INFO 31740 --- [ main] org.reflections.Reflections : Reflections took 28 ms to scan 1 urls, producing 1 keys and 2 values
2022-10-13 08:49:18.561 INFO 31740 --- [ main] org.reflections.Reflections : Reflections took 4 ms to scan 1 urls, producing 1 keys and 2 values
2022-10-13 08:49:18.916 INFO 31740 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-10-13 08:49:18.928 INFO 31740 --- [ main] n.g.p.m.DFDatabaseMigrationsApplication : Started DFDatabaseMigrationsApplication in 3.022 seconds (JVM running for 5.219)
2022-10-13 08:49:18.945 INFO 31740 --- [ main] i.m.r.c.e.o.migrate.MigrateExecutorBase : Mongock skipping the data migration. All change set items are already executed or there is no change set item.
2022-10-13 08:49:18.945 INFO 31740 --- [ main] i.m.driver.core.lock.LockManagerDefault : Mongock releasing the lock
2022-10-13 08:49:18.945 INFO 31740 --- [ main] i.m.driver.core.lock.LockManagerDefault : Mongock releasing the lock
2022-10-13 08:49:18.962 INFO 31740 --- [ main] i.m.driver.core.lock.LockManagerDefault : Mongock released the lock
2022-10-13 08:49:18.962 INFO 31740 --- [ main] i.m.r.c.e.o.migrate.MigrateExecutorBase : Mongock has finished

PRIORITY

NORMAL

Version and environment

Mongock

  • Mongock version: 5.1.6
  • Spring Boot project
  • Using annotation approach

Environment

  • Framework and libraries versions. Especially those that affect directly to Mongock(Spring, Spring data, MongoDB driver, etc.)
  • Infrastructure: Kubernetes, Docker, SO, etc.

Steps to Reproduce

  1. Run application

Behaviour

How often the bug happens: 100%

Additional context

application.yaml file
image

Application Log Output:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationRunner' defined in io.mongock.runner.springboot.config.MongockContext: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.mongock.runner.springboot.base.MongockApplicationRunner]: Factory method 'applicationRunner' threw exception; nested exception is io.mongock.api.exception.MongockException: Property transaction-enabled=true, but transactionManager not provided
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.20.jar:5.3.20]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.20.jar:5.3.20]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.0.jar:2.7.0]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.0.jar:2.7.0]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.0.jar:2.7.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.0.jar:2.7.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar:2.7.0]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar:2.7.0]
at ntt.global.platform.migrations.DFDatabaseMigrationsApplication.main(DFDatabaseMigrationsApplication.java:13) ~[classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.mongock.runner.springboot.base.MongockApplicationRunner]: Factory method 'applicationRunner' threw exception; nested exception is io.mongock.api.exception.MongockException: Property transaction-enabled=true, but transactionManager not provided
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.20.jar:5.3.20]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.20.jar:5.3.20]
... 19 common frames omitted

Caused by: io.mongock.api.exception.MongockException: Property transaction-enabled=true, but transactionManager not provided
at io.mongock.runner.core.builder.RunnerBuilderBase.validateConfigurationAndInjections(RunnerBuilderBase.java:212) ~[mongock-runner-core-5.1.6.jar:na]
at io.mongock.runner.springboot.base.builder.SpringbootBuilderBase.validateConfigurationAndInjections(SpringbootBuilderBase.java:136) ~[mongock-springboot-base-5.1.6.jar:na]
at io.mongock.runner.core.builder.RunnerBuilderBase.buildRunner(RunnerBuilderBase.java:144) ~[mongock-runner-core-5.1.6.jar:na]
at io.mongock.runner.core.builder.RunnerBuilderBase.buildRunner(RunnerBuilderBase.java:134) ~[mongock-runner-core-5.1.6.jar:na]
at io.mongock.runner.core.builder.RunnerBuilderBase.buildRunner(RunnerBuilderBase.java:129) ~[mongock-runner-core-5.1.6.jar:na]
at io.mongock.runner.springboot.base.builder.SpringbootBuilderBase.buildApplicationRunner(SpringbootBuilderBase.java:102) ~[mongock-springboot-base-5.1.6.jar:na]
at io.mongock.runner.springboot.base.config.MongockContextBase.applicationRunner(MongockContextBase.java:27) ~[mongock-springboot-base-5.1.6.jar:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.20.jar:5.3.20]
... 20 common frames omitted

We'll be looking at this asap

Hello @CiaranMc93 , did you solve this issue? If not, please could you check this springboot-quickstart example, because the error you are getting is related to the injection of TransactionManager (it seems you are not providing it).

You need to inject it this way:

    @Bean
    public MongoTransactionManager transactionManager(MongoTemplate mongoTemplate) {
        TransactionOptions transactionalOptions = TransactionOptions.builder()
                .readConcern(ReadConcern.MAJORITY)
                .readPreference(ReadPreference.primary())
                .writeConcern(WriteConcern.MAJORITY.withJournal(true))
                .build();
        return new MongoTransactionManager(mongoTemplate.getMongoDbFactory(), transactionalOptions);
    }

Closed due to inactivity.