- CDI extension for HikariCP
This CDI portable extension provides support for injecting HikariCP data sources in your Helidon MicroProfile applications.
Maven Coordinates
To enable HikariCP Support add the following dependency to your project’s pom.xml (see Managing Dependencies).
<dependency>
<groupId>io.helidon.integrations.cdi</groupId>
<artifactId>helidon-integrations-cdi-datasource-hikaricp</artifactId>
</dependency>content_copy
Injecting a HikariCP data source
The following examples show how to create a DataSource named orders in your application.
Field-injection example
@Inject
@Named("orders")
private DataSource ordersDataSource;content_copy
Constructor-injection example
private final DataSource ds;
@Inject
public YourConstructor(@Named("orders") DataSource ds) {
super();
this.ds = ds;
}content_copy
The extension implements this injection point by creating a HikariDataSource object in the application scope.
You can configure the object using MicroProfile config. For example, the data source created above can be configured as follows:
META-INF/microprofile-config.properties
javax.sql.DataSource.orders.dataSourceClassName=oracle.jdbc.pool.OracleDataSource
javax.sql.DataSource.orders.dataSource.url = jdbc:oracle:thin:@localhost:1521:ORCL
javax.sql.DataSource.orders.dataSource.user = sys as sysoper
javax.sql.DataSource.orders.dataSource.password = Oraclecontent_copy
Property names that start with javax.sql.DataSource.dataSourceName. are parsed, and the remaining portion of each name is treated as a Hikari connection pool property.