'Spring data JPA: Log datasource used in transaction in case of AbstractRoutingDataSource
I am using AbstractRoutingDataSource to achieve read replica connection as mentioned in below link: https://vladmihalcea.com/read-write-read-only-transaction-routing-spring/
I want to print the transaction boundary and for that, I have added the below properties in the application.properties file:
logging.level.org.springframework.orm.jpa: DEBUG
logging.level.org.springframework.transaction: DEBUG
With this the transaction boundary related logs are getting printed properly as below: e.g.
o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name
o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(1338079933<open>)] for JPA transaction
o.s.orm.jpa.JpaTransactionManager : Suspending current transaction, creating new transaction with name
o.s.orm.jpa.JpaTransactionManager : Opened new EntityManager [SessionImpl(1161368013<open>)] for JPA transaction
o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(1161368013<open>)]
o.s.orm.jpa.JpaTransactionManager : Closing JPA EntityManager [SessionImpl(1161368013<open>)] after transaction
Along with this, I also want to print the data source or hikari pool name that is used in transaction. i.e. any information that can identify which data source is used by this transaction.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
