HikariCP
HikariCP copied to clipboard
In HikariJNDIFactory, int[] type property of DataSource cannot be set.
I am trying to connect to AWS Aurora (Postgres) using HikariJNDIFactory on Tomcat 9.
Below is the META-INF/context.xml of the war to be deployed in Tomcat.
<Context>
<Resource name="dataSourceForRead"
uniqueName="dataSourceForRead"
factory="com.zaxxer.hikari.HikariJNDIFactory"
type="javax.sql.DataSource"
dataSourceClassName="org.postgresql.ds.PGSimpleDataSource"
auth="Container"
minimumIdle="1"
maximumPoolSize="10"
dataSource.url="jdbc:postgresql://xxxxx.cluster-xxxxx.ap-northeast-1.rds.amazonaws.com:5432,xxxxx.cluster-ro-xxxxx.ap-northeast-1.rds.amazonaws.com:5432/databasename"
dataSource.serverNames="postgresql://xxxxx.cluster-xxxxx.ap-northeast-1.rds.amazonaws.com,xxxxx.cluster-ro-xxxxx.ap-northeast-1.rds.amazonaws.com"
dataSource.portNumbers="5432,5432"
dataSource.databaseName="databasename"
dataSource.user="postgres"
dataSource.password="xxxxxxxx"
dataSource.sslMode="disable"
dataSource.loginTimeout="2"
dataSource.connectTimeout="2"
dataSource.cancelSignalTimeout="2"
dataSource.socketTimeout="60"
dataSource.tcpKeepAlive="true"
dataSource.loadBalanceHosts="true"
dataSource.readOnly="true"
dataSource.targetServerType="preferSecondary"
dataSource.applicationName="web"/>
</Context>
Because there is a master and a read replica, there are multiple hostnames and port numbers for the database.
Therefore, I am trying to set them using the properties serverNames and portNumbers in DataSource.
However, the following exception occurred
java.lang.IllegalArgumentException: argument type mismatch
com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:163)
com.zaxxer.hikari.util.PropertyElf.lambda$setTargetFromProperties$0(PropertyElf.java:51)
java.base\/java.util.concurrent.ConcurrentHashMap.forEach(ConcurrentHashMap.java:1603)
java.base\/java.util.Properties.forEach(Properties.java:1422)
com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:46)
com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:324)
com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:113)
com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:91)
com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80)
com.zaxxer.hikari.HikariJNDIFactory.createDataSource(HikariJNDIFactory.java:63)
com.zaxxer.hikari.HikariJNDIFactory.getObjectInstance(HikariJNDIFactory.java:51)
org.apache.naming.factory.FactoryBase.getObjectInstance(FactoryBase.java:96)
java.naming\/javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:342)
org.apache.naming.NamingContext.lookup(NamingContext.java:864)
org.apache.naming.NamingContext.lookup(NamingContext.java:158)
org.apache.naming.NamingContext.lookup(NamingContext.java:850)
org.apache.naming.NamingContext.lookup(NamingContext.java:158)
org.apache.naming.NamingContext.lookup(NamingContext.java:850)
org.apache.naming.NamingContext.lookup(NamingContext.java:172)
org.apache.naming.SelectorContext.lookup(SelectorContext.java:161)
java.naming\/javax.naming.InitialContext.lookup(InitialContext.java:409)
Looking at the HikariCP implementation, it seems that injections into int[] and String[] properties are not supported. https://github.com/brettwooldridge/HikariCP/blob/dev/src/main/java/com/zaxxer/hikari/util/PropertyElf.java#L112-L165
I would like to be able to set the int[] and String[] properties of the DataSource as well.