在HikariCP中配置SQLite的date_string_format

时间:2016-01-15 16:09:28

标签: sqlite hikaricp

我们正在将C3P0迁移到HikarCP \ o /,除了我们要覆盖的属性date_string_format的配置外,一切正常。

以下是我们旧的C3P0配置:

<bean id="defaultDataSource" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource">
      <property name="driverClass" value="org.sqlite.SQLiteDataSource" />
      ...
      <property name="properties">
         <map value-type="java.lang.String" key-type="java.lang.String">
            <entry key="date_string_format" value="${datasource.date_string_format:''}" />
         </map>
      </property>
   </bean>

我们的HikariCP配置:

<bean id="merlinDataSourceConfig" class="com.zaxxer.hikari.HikariConfig">
      <property name="dataSourceClassName" value="org.sqlite.SQLiteDataSource" />
      ...
      <property name="registerMbeans" value="true"/>
      <property name="dataSourceProperties">
         <props>
            <prop key="date_string_format">${datasource.date_string_format:''}</prop>
         </props>
      </property>
   </bean>

我们收到了这个错误:

Method not found: setDate_string_format
    java.beans.PropertyDescriptor.<init>(Unknown Source)
    com.zaxxer.hikari.util.PropertyBeanSetter.setProperty(PropertyBeanSetter.java:125)
    com.zaxxer.hikari.util.PropertyBeanSetter.setTargetFromProperties(PropertyBeanSetter.java:63)
    com.zaxxer.hikari.pool.PoolUtilities.initializeDataSource(PoolUtilities.java:111)
    com.zaxxer.hikari.pool.BaseHikariPool.<init>(BaseHikariPool.java:157)
    com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:60)
    com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:48)
    com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

有关如何解决此问题的想法吗?

由于

1 个答案:

答案 0 :(得分:1)

不知道C3P0是如何工作的,但在HikariCP dataSourceProperties中将映射到针对DataSource类的方法调用。因此,像date_string_format这样的属性将映射到在SQLiteDataSource上查找名为setDate_string_format()的setter。没有这样的二传手。尝试以下几点:

<bean id="sqliteConfig" class="org.sqlite.SQLiteConfig">
  <constructor-arg>
    <props>
      <prop key="date_string_format">${datasource.date_string_format:''}</prop>
    </props>
  <constructor-arg>
</bean>

<bean id="merlinDataSourceConfig" class="com.zaxxer.hikari.HikariConfig">
  <property name="dataSource">
    <bean id="sqlLiteDataSource" class="org.sqlite.SQLiteDataSource">
      <constructor-arg ref="sqliteConfig" />
    </bean>
  </property>
  ...
  <property name="registerMbeans" value="true"/>
</bean>

您当然可以嵌套/不需要<bean>声明,并添加/删除refs

欢迎继续使用dataSourceProperties任何&#34; setter&#34;公开在SQLiteDataSource(JavaDoc here)。