问题
is it possible to intercept the connection pooling mechanism of a DataSource in a JEE container?
For (un)setting some information on the connection's context I'm searching for a way to intercept the pooling mechanism so that I know when and which connection is put back into the pool.
So does anyone know a (common) way to do this?
Some additional info:
- The application runs on Wildfly
- Using Hibernate for ORM
回答1:
The option connection-listener
in datasource configuration can be the solution.
connection-listener:
An
org.jboss.jca.adapters.jdbc.spi.listener.ConnectionListener
that provides a possible to listen for connection activation and passivation in order to perform actions before the connection is returned to the application or returned to the pool
You can create a custom implementation of org.jboss.jca.adapters.jdbc.spi.listener.ConnectionListener
and deploy it as a module to do that you want.
来源:https://stackoverflow.com/questions/41715182/intercept-connection-pooling-of-datasource-connections-in-jee-container