class MyService {
def dataSourceUnproxied
...
}
4.4.3 Transaction-aware DataSource Proxy
Version: 3.3.10
4.4.3 Transaction-aware DataSource Proxy
The actual dataSource
bean is wrapped in a transaction-aware proxy so you will be given the connection that’s being used by the current transaction or Hibernate Session
if one is active.
If this were not the case, then retrieving a connection from the dataSource
would be a new connection, and you wouldn’t be able to see changes that haven’t been committed yet (assuming you have a sensible transaction isolation setting, e.g. READ_COMMITTED
or better).
The "real" unproxied dataSource
is still available to you if you need access to it; its bean name is dataSourceUnproxied
.
You can access this bean like any other Spring bean, i.e. using dependency injection:
or by pulling it from the ApplicationContext
:
def dataSourceUnproxied = ctx.dataSourceUnproxied