1

I have a simple Tomcat application setup to use a MySQL data source with a custom DataSourceFactory. The context.xml is give below. The custom factory is used merely to the placeholders ({{driver}}) with actual values at runtime.

<Context displayName="Foo" path="/foo">
    <Resource name="jdbc/MySQLDB"
              auth="Container"
              type="javax.sql.DataSource"
              maxTotal="{{maxTotal}}"
              maxIdle="{{maxIdle}}"
              ...
              driverClassName="{{driver}}"
              username="{{user}}"
              password="{{password}}"
              url="{{url}}"
              factory="com.example.CustomDataSourceFactory" />
</Context>

The application uses Guice to inject DataSource instances:

bind(DataSource.class).toProvider(fromJndi(DataSource.class, "java:comp/env/jdbc/MySQLDB"));

How can I wrap my MySQL DataSource using a flexy-pool FlexyPoolDataSource?

I checked out the documentation and did the following:

  1. Added the necessary dependencies (flexy-pool-core, flexy-java-ee)
  2. Added a flexy-pool.properties file at resources root (contents below)
flexy.pool.data.source.unique.name=flexy-pool-dataSource
flexy.pool.data.source.jndi.name=jdbc/MySQLDB
flexy.pool.metrics.reporter.jmx.auto.start=true

I'm stuck - how can I make the CustomDataSourceFactory work with flexy-pool? What should I change and how?

Manoj Govindan
  • 72,339
  • 21
  • 134
  • 141
  • FWIW the `CustomDataSourceFactory` extends `org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory` – Manoj Govindan Oct 25 '21 at 17:46
  • Solution: currently the `CustomDataSourceFactory` is returning an instance of `DataSource`. Wrap it in `FlexyPoolDataSource` and return the wrapped instance instead. Now trying to figure out how to observe metrics. – Manoj Govindan Oct 26 '21 at 04:25

0 Answers0