我正在尝试使用基于xml的Bean配置为基于Spring的应用程序使用Hikari连接池。下面是我的Hikari配置bean,我正在使用Db2作为数据库。
<bean id="HikariConfig_UId_Primary" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="uidPrimaryCP" />
<property name="connectionTestQuery" value="select 1 from sysibm.systables fetch first row only with UR" />
<property name="dataSourceClassName" value="${Jdbc_DataSourceClassName}" />
<property name="maximumPoolSize" value="${Jdbc_MaxPoolSize}"/>
<property name="idleTimeout" value="${Jdbc_IdleTimeOut}" />
<property name="maxLifetime" value="${Jdbc_MaxLifeTime}" />
<property name="connectionTimeout" value="${Jdbc_ConnTimeOut}" />
<property name="dataSourceProperties">
<props>
<prop key="url">${Jdbc_UID_Primary}</prop>
<prop key="user">${Jdbc_UserId}</prop>
<prop key="password">${Jdbc_Password}</prop>
</props>
</property>
</bean>
<bean id="UID_Primary_DataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="HikariConfig_UId_Primary" />
</bean>
无法注册Bean,表示数据库url属性-目标类com.ibm.db2.jcc.DB2SimpleDataSource上不存在url。 下面是完整的堆栈跟踪。.
com.ibm.ws.webcontainer.webapp.WebApp notifyServletContextCreated SRVE0283E: Exception caught while initializing context: {0}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UID_Primary_DataSource' defined in class path resource [config/SpringDbContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.zaxxer.hikari.HikariDataSource]: Constructor threw exception; nested exception is java.lang.RuntimeException: Property url does not exist on target class com.ibm.db2.jcc.DB2SimpleDataSource
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:278)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.deere.u90.iafservice.unifieduser.application.ApplicationRegistry.loadSpringLdapContext(ApplicationRegistry.java:
非常感谢您的帮助。
谢谢..
答案 0 :(得分:0)
我已使用Spring Boot连接到 Hikari ,但未使用 xml 配置进行连接。请参阅我的帖子here
我认为,将以下属性加起来应该可以修复错误。
<property name="jdbcUrl" value="" />
<property name="username" value="" />
<property name="password" value="" />
答案 1 :(得分:0)
您似乎有几处错误。您没有发布变量$ {Jdbc_DataSourceClassName}的值,因为它似乎在运行时解析为DB2SimpleDataSource。对于this IBM KnowledgeCenter topic,该数据源不可池化,并且由于您以“我正在尝试使用Hikari连接池”开始文章,所以我假设您想要像com.ibm.db2.jcc.DB2ConnectionPoolDataSource这样的可池化DS作为描述here。 第二个问题是DB2 Datasource类不支持url属性,只有DB2 DriverManager接口支持它。
是DB2数据源类的抽象基础的KC主题DB2BaseDataSource。您可以在数据源或url参数中设置所有属性 一个DriverManager.getConnection调用。
url并非列出的属性之一,因此您将需要使用主机名,端口等属性建立与数据源的连接