我想在我的 Spring 4.0.3 上下文中使用Hikari CP,但似乎我遗漏了一些东西。
我的 bean 配置如下所示:
<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 org.hsqldb.jdbc.JDBCDataSource配置 dataSourceClassName
那样:
<prop key="dataSourceClassName">org.hsqldb.jdbc.JDBCDataSource</prop>
也是这样:
<prop key="dataSource.ClassName">org.hsqldb.jdbc.JDBCDataSource</prop>
两次我都有以下异常:
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
有人可以向我展示一个与 HSQL DB 一起工作的Hikari CP Spring 4 bean 配置吗?
我对 MySql、PG 等不感兴趣,因为我知道如何让它们工作。但我无法用 HSQL 完成它。
谢谢,
使用的技术:Java8、Spring 4.0.3、HSQL 2.3.2