I have a micronaut-data application and for a copy operation I need to use the same JPA repository to access multiple datasources. I would like to inject them into different variable, e.g. sourceRepo
and targetRepo
. The datasources are declared in the application.yml
with the names default and target. If I declare a repository variable with @Inject
it will be initialized to access the default datasource.
The question is, how can I declare an injected repository variable so that it will access the target datasource? I can declare target injections of EntityManager
or SynchronousTransactionManager
like below and these work. But neither of these annotations has an effect on a repository variable or parameter.
@Inject
@CurrentSession("target")
EntityManager entityManager;
@PersistenceContext(name = "target")
SynchronousTransactionManager<Connection> transactionManager;