获取:java.lang.IllegalStateException:无法将类型 [java.lang.String] 的值转换为所需类型 [javax.sql.DataSource]

Getting : java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource]

我正在使用 Spring 3.2.13 jar 和 ibatis 2.3.4.726 版本来设置数据源,如下所示

我收到以下异常 Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found

我的xmlSpring配置如下:

<bean id="commonDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/ds_GOLD" />
    <property name="defaultObject" value="jdbc/ds_SILVERR" />
</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation">
        <value>
            classpath:com/dav/dao/config/sqlMapConfig.xml
        </value>
    </property>
    <property name="dataSource">
        <ref bean="commonDataSource" />
    </property>
    <property name="transactionConfigClass">
        <value>com.ibatis.sqlmap.engine.transaction.external.ExternalTransactionConfig
        </value>
    </property>
    <property name="transactionConfigProperties">
        <props>
            <prop key="DefaultAutoCommit">false</prop>
            <prop key="SetAutoCommitAllowed">false</prop>
        </props>
    </property>
</bean>

配置对我来说似乎不错,但出现异常 仅当 "jdbc/ds_GOLD" 未在应用服务器中配置时。在这种情况下,应该选择 defaultObject JNDI。如果 "jdbc/ds_GOLD" 在应用程序服务器中配置,我在日志中看不到任何错误。但是故障转移情况下它不起作用。

[5/1/16 3:32:51:329 EDT] 00000098 webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0296E: [glow#glow.war][/glow][Servlet.LOG]:.StrutsServlet: null:.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gcdSqlMapClient' defined in ServletContext resource [/WEB-INF/config/common-dao.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.sql.DataSource' for property 'dataSource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] 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:529)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:293)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:618)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)
    .
    .
    . 
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1862)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.sql.DataSource' for property 'dataSource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:464)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:495)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:489)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1465)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1424)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    ... 114 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267)
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:449)
    ... 120 more
 ``

忘记将 defaultObject 保留为对数据源的 属性 引用。我错误地将其配置为 属性 值。