是否可以拦截JEE容器中DataSource的连接池机制?
为了(取消)设置连接上下文的一些信息,我正在寻找一种拦截池机制的方法,以便我知道何时以及哪个连接被放回池中。
那么有人知道一种(常见)方法吗?
一些附加信息:
- 应用程序在 Wildfly 上运行
- 使用 Hibernate 进行 ORM
最佳答案
数据源配置中的选项connection-listener
可以作为解决方案。
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
您可以创建 org.jboss.jca.adapters.jdbc.spi.listener.ConnectionListener
的自定义实现,并将其部署为模块来执行您想要的操作。
关于java - JEE容器中数据源连接的拦截连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41715182/