问题描述
我想在我的Spring 4.0.3环境中使用,但似乎我遗漏了一些东西。
i want to use Hikari CP in my Spring 4.0.3 context but seems i am missing something.
我的bean配置如下:
My bean configuration looks like:
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariConfig">
<constructor-arg>
<props>
<prop key="dataSource.driverClassName">${database.driver}</prop>
<prop key="dataSource.jdbcUrl">${database.database.jdbc.url}</prop>
<prop key="dataSource.port">${database.port}</prop>
<prop key="dataSource.databaseName">${database.name}</prop>
<prop key="dataSource.user">${database.user}</prop>
<prop key="dataSource.password">${database.password}</prop>
</props>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
但我得到一个例外:
Caused by: java.lang.IllegalArgumentException: one of either dataSource or dataSourceClassName must be specified
at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:655)
at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:66)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
... 15 more
我试图使用HSQL配置dataSourceClassName
i have tried to configure dataSourceClassName using the HSQL org.hsqldb.jdbc.JDBCDataSource
这样:
<prop key="dataSourceClassName">org.hsqldb.jdbc.JDBCDataSource</prop>
同样如此:
<prop key="dataSource.ClassName">org.hsqldb.jdbc.JDBCDataSource</prop>
两次我都得到以下例外:
both times i got the following exception:
Caused by: java.lang.RuntimeException: java.beans.IntrospectionException: Method not found: setPort
at com.zaxxer.hikari.util.PropertyBeanSetter.setProperty(PropertyBeanSetter.java:109)
at com.zaxxer.hikari.util.PropertyBeanSetter.setTargetFromProperties(PropertyBeanSetter.java:61)
at com.zaxxer.hikari.pool.HikariPool.initializeDataSource(HikariPool.java:497)
... 23 more
Caused by: java.beans.IntrospectionException: Method not found: setPort
at java.beans.PropertyDescriptor.<init>(PropertyDescriptor.java:110)
at com.zaxxer.hikari.util.PropertyBeanSetter.setProperty(PropertyBeanSetter.java:97)
... 25 more
有人能给我看一个 Hikari CP Spring 4 bean配置,可以与HSQL DB一起使用吗?
Can someone show me a working Hikari CP Spring 4 bean configuration that works with a HSQL DB?
我不感兴趣在MySql,PG等中,因为我知道如何让它们工作。但我无法通过HSQL完成它。
I am not interested in MySql, PG etc. because i know how to get them working. But i can't manage to get it done with HSQL.
谢谢,
使用的技术:Java8, Spring 4.0.3,HSQL 2.3.2
Tech used: Java8, Spring 4.0.3, HSQL 2.3.2
推荐答案
完成工作的一种方法是提供DataSource对象的实例:
one way to get the job done is to provide an instance of a DataSource object:
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariConfig">
<property name="dataSource">
<bean class="org.hsqldb.jdbc.JDBCDataSource">
<property name="url" value="${database.database.jdbc.url}"/>
<property name="databaseName" value="${database.name}"/>
<property name="user" value="${database.user}"/>
<property name="password" value="${database.password}"/>
</bean>
</property>
</bean>
</constructor-arg>
</bean>
肯定还有其他解决方案。
for sure there are other solutions.
HTH,
这篇关于如何在Spring(4)上下文中为HSQL配置Hikari CP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!