Setup:
- micronaut 3.7.2
- micronaut-data 3.8.1, micronaut-data-r2dbc, r2dbc-postgresql 0.9.2
- Flyway 8.5.13, micronaut-jdbc-hikari, micronaut-flyway 5.4.1, postgresql 42.5.0
- testcontainers (jdbc, r2dbc, postgresql) 1.17.5
- io.micronaut.test-resources 3.6.2
Test Configuration (conf4k):
datasources {
default {
dialect=POSTGRES
options {
currentSchema=default
}
}
}
r2dbc {
datasources {
default {
dialect=POSTGRES
options {
currentSchema=default
}
}
}
}
flyway {
datasources {
default {
enabled=true
locations="classpath:databasemigrations"
schemas=["default"]
create-schemas=true
}
}
}
test-resources {
containers {
postgres {
image-name="postgres:12.12"
hostnames=["localhost"]
}
}
}
Preconditions:
To make Flyway and micronaut data use the same database and testcontainer, the datasource of both needs to be named alike.
Problem:
Because of JDBC and R2DBC beeing used at the same time, synchronous and reactive TransactionManagers beans are created and I get the following error, when I use @Transactional:
Multiple possible bean candidates found: [io.micronaut.transaction.jdbc.DataSourceTransactionManager, io.micronaut.transaction.sync.SynchronousFromReactiveTransactionManager]
Thoughts:
I thought, I could solve that with @TransactionalAdvice, but since both datasources need to have the same name, this is not possible. I tried to name the datasources differently, but does not work at all.