Spring   发布时间:2022-04-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用Spring jdbcTemplate时的ConnectionPooling配置 大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在开发一个需要在大型机上调用DB2函数以获得ID的应用程序.

在我的spring应用程序上下文中,我定义了jdbc模板,从而可以在zOS上查询DB2:

    <bean id="jdbcTemplateDB2"
       class="org.springframework.jdbc.core.JdbcTemplate">
         <property name="datasource" ref="datasourceDB2"/>
    </bean>

然后,我将数据源定义如下:

 <bean id="datasourceDB2" 
    class="com.ibm.db2.jcc.DB2Datasource">
        <property name="serverName" value="hostname" />
        <property name="portnumber" value="portno"/>
        <property name="databasename" value="dbname"/>
        <property name="driverType" value="4"/>
        <property name="user" value="userid"/>
        <property name="password" value="password"/>
 </bean>

以上作品.
但是,在ibm的db2jcc.jar文件中,我看到具有连接池的数据源类-com.ibm.db2.jcc.DB2ConnectionPoolDatasource.所以我试图用它代替上面的那个-像这样:

 <bean id="datasourceDB2"
    class="com.ibm.db2.jcc.DB2ConnectionPoolDatasource">
        <property name="serverName" value="hostname" />
        <property name="portnumber" value="portno"/>
        <property name="databasename" value="dbname"/>
        <property name="driverType" value="4"/>
        <property name="user" value="userid"/>
        <property name="password" value="password"/>
 </bean>

但是,使用DB2ConnectionPoolDatasource给我以错误.

CAnnot convert value of type [com.ibm.db2.jcc.DB2ConnectionPoolDatasource] to required type [javax.sql.Datasource] for property 'datasource': no matching editors or conversion strategy found

完整的stackTrace如下

    Exception in thread "main" org.springframework.beans.factory.beanCreationException: Error creaTing bean with name 'classUniquEIDDaoImpl_v2': Injection of resource dependencies Failed; nested exception is org.springframework.beans.factory.beanCreationException: Error creaTing bean with name 'jdbcTemplateDB2' defined in class path resource [Meta-INF/spring/applicationContext-db2.xml]: Initialization of bean Failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.ibm.db2.jcc.DB2ConnectionPoolDatasource' to required type 'javax.sql.Datasource' for property 'datasource'; nested exception is java.lang.IllegalStateException: CAnnot convert value of type [com.ibm.db2.jcc.DB2ConnectionPoolDatasource] to required type [javax.sql.Datasource] for property 'datasource': no matching editors or conversion strategy found
        at org.springframework.context.Annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:307)
        at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.populateBean(AbstractAutowireCapablebeanfactory.java:1106)
        at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:517)
        at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:456)
        at org.springframework.beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:291)
        at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:193)
        at org.springframework.beans.factory.support.DefaultListablebeanfactory.preInstantiateSingletons(DefaultListablebeanfactory.java:609)
        at org.springframework.context.support.AbstractApplicationContext.finishbeanfactoryInitialization(AbstractApplicationContext.java:918)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        at com.slma.euclid.core.dao.MainDB2.main(MainDB2.java:18)
    Caused by: org.springframework.beans.factory.beanCreationException: Error creaTing bean with name 'jdbcTemplateDB2' defined in class path resource [Meta-INF/spring/applicationContext-db2.xml]: Initialization of bean Failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.ibm.db2.jcc.DB2ConnectionPoolDatasource' to required type 'javax.sql.Datasource' for property 'datasource'; nested exception is java.lang.IllegalStateException: CAnnot convert value of type [com.ibm.db2.jcc.DB2ConnectionPoolDatasource] to required type [javax.sql.Datasource] for property 'datasource': no matching editors or conversion strategy found
        at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:527)
        at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.createBean(AbstractAutowireCapablebeanfactory.java:456)
        at org.springframework.beans.factory.support.Abstractbeanfactory$1.getObject(Abstractbeanfactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.Abstractbeanfactory.doGetBean(Abstractbeanfactory.java:291)
        at org.springframework.beans.factory.support.Abstractbeanfactory.getBean(Abstractbeanfactory.java:193)
        at org.springframework.beans.factory.support.DefaultListablebeanfactory.findAutowireCandidates(DefaultListablebeanfactory.java:876)
        at org.springframework.beans.factory.support.DefaultListablebeanfactory.doResolveDependency(DefaultListablebeanfactory.java:818)
        at org.springframework.beans.factory.support.DefaultListablebeanfactory.resolveDependency(DefaultListablebeanfactory.java:735)
        at org.springframework.context.Annotation.CommonAnnotationBeanPostProcessor.autowireresource(CommonAnnotationBeanPostProcessor.java:439)
        at org.springframework.context.Annotation.CommonAnnotationBeanPostProcessor.getresource(CommonAnnotationBeanPostProcessor.java:417)
        at org.springframework.context.Annotation.CommonAnnotationBeanPostProcessor$resourceElement.getresourceToInject(CommonAnnotationBeanPostProcessor.java:559)
        at org.springframework.beans.factory.Annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)
        at org.springframework.beans.factory.Annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
        at org.springframework.context.Annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:304)
        ... 13 more
    Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.ibm.db2.jcc.DB2ConnectionPoolDatasource' to required type 'javax.sql.Datasource' for property 'datasource'; nested exception is java.lang.IllegalStateException: CAnnot convert value of type [com.ibm.db2.jcc.DB2ConnectionPoolDatasource] to required type [javax.sql.Datasource] for property 'datasource': no matching editors or conversion strategy found
        at org.springframework.beans.beanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:485)
        at org.springframework.beans.beanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516)
        at org.springframework.beans.beanWrapperImpl.convertForProperty(BeanWrapperImpl.java:510)
        at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.convertForProperty(AbstractAutowireCapablebeanfactory.java:1406)
        at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.applyPropertyValues(AbstractAutowireCapablebeanfactory.java:1365)
        at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.populateBean(AbstractAutowireCapablebeanfactory.java:1118)
        at org.springframework.beans.factory.support.AbstractAutowireCapablebeanfactory.doCreateBean(AbstractAutowireCapablebeanfactory.java:517)
        ... 27 more
    Caused by: java.lang.IllegalStateException: CAnnot convert value of type [com.ibm.db2.jcc.DB2ConnectionPoolDatasource] to required type [javax.sql.Datasource] for property 'datasource': no matching editors or conversion strategy found
        at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:241)
        at org.springframework.beans.beanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470)
        ... 33 more

我究竟做错了什么?在实例化Spring JdbcTemplate时使用连接池数据源的正确方法是什么?

任何帮助表示赞赏.

-SGB

最佳答案
您读过这个:http://forum.springsource.org/showthread.php?66142-How-to-use-javax-sql-datasource-with-a-ConnectionPoolDataSource

它说com.ibm.db2.jcc.DB2Datasource如果已正确使用,则已经是一个连接池.

大佬总结

以上是大佬教程为你收集整理的使用Spring jdbcTemplate时的ConnectionPooling配置 全部内容,希望文章能够帮你解决使用Spring jdbcTemplate时的ConnectionPooling配置 所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。