Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [E:\yz-soft-new\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\jazfcg_demo\WEB-INF\classes\spring\spring-mybatis.xml]: Cannot resolve reference to bean 'dynamicDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dynamicDataSource' defined in file [E:\yz-soft-new\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\jazfcg_demo\WEB-INF\classes\spring\spring-mybatis.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'targetDataSources' with key [TypedStringValue: value [dataSource], target type [class java.lang.String]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in file [E:\yz-soft-new\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\jazfcg_demo\WEB-INF\classes\spring\spring-mybatis.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcDriver' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'jdbcDriver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1477) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
... 50 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dynamicDataSource' defined in file [E:\yz-soft-new\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\jazfcg_demo\WEB-INF\classes\spring\spring-mybatis.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'targetDataSources' with key [TypedStringValue: value [dataSource], target type [class java.lang.String]]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in file [E:\yz-soft-new\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\jazfcg_demo\WEB-INF\classes\spring\spring-mybatis.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcDriver' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'jdbcDriver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:407) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:165) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1477) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
... 60 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in file [E:\yz-soft-new\.metadata\.plugins\org.eclipse.wst.server.core\tmp3\wtpwebapps\jazfcg_demo\WEB-INF\classes\spring\spring-mybatis.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcDriver' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'jdbcDriver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
... 72 common frames omitted
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcDriver' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'jdbcDriver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1076) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:927) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]

解决方案 »

  1.   

    <bean  class="com.yzsoft.base.dao.DaoPostProcessor" />  
    <bean id="propertyConfigurer"  
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
            <property name="locations">  
                <list>  
                    <value>classpath:properties/dev.system.properties</value>  
                </list>  
            </property>  
        </bean>   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="jdbcDriver" value="${mybatis.jdbcDriver}" />
    <property name="jdbcUrl" value="${mybatis.jdbcUrl}" />
    <property name="user" value="${mybatis.user}" />
    <property name="password" value="${mybatis.password}" />
    <property name="maxActive" value="${mybatis.maxActive}" />  
        <property name="maxIdle" value="${mybatis.maxIdle}" />  
        <property name="minIdle" value="${mybatis.minIdle}" />  
        <property name="removeAbandoned" value="${mybatis.removeAbandoned}" />  
        <property name="removeAbandonedTimeout" value="${mybatis.removeAbandonedTimeout}" />  
        <property name="logAbandoned" value="${mybatis.logAbandoned}" />  
        <property name="defaultAutoCommit" value="${mybatis.defaultAutoCommit}" />  
        <property name="defaultReadOnly" value="${mybatis.defaultReadOnly}" /> 
    </bean>
    <bean id="dataSourceTwo" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="jdbcDriver" value="${mybatis.jdbcDriver1}" />
    <property name="jdbcUrl" value="${mybatis.jdbcUrl1}" />
    <property name="user" value="${mybatis.user1}" />
    <property name="password" value="${mybatis.password1}" />
    <property name="maxActive" value="${mybatis.maxActive1}" />  
        <property name="maxIdle" value="${mybatis.maxIdle1}" />  
        <property name="minIdle" value="${mybatis.minIdle1}" />  
        <property name="removeAbandoned" value="${mybatis.removeAbandoned1}" />  
        <property name="removeAbandonedTimeout" value="${mybatis.removeAbandonedTimeout1}" />  
        <property name="logAbandoned" value="${mybatis.logAbandoned1}" />  
        <property name="defaultAutoCommit" value="${mybatis.defaultAutoCommit1}" />  
        <property name="defaultReadOnly" value="${mybatis.defaultReadOnly1}" /> 
    </bean>
    <bean id="dynamicDataSource" class="sys.EmailTask">  
            <property name="targetDataSources">  
                <map key-type="java.lang.String">  
                    <entry value-ref="dataSource" key="dataSource"></entry>  
                    <entry value-ref="dataSourceTwo" key="dataSourceTwo"></entry>  
                </map>  
            </property>  
            <property name="defaultTargetDataSource" ref="dataSource">  
            </property>  
        </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dynamicDataSource" />
    <!-- 自动取对应包中不包括包名的类名作为类型别名,多个包之间可以用逗号或分号分开 -->
    <property name="typeAliasesPackage" value="com.yzsoft.orm" />
    <!--configLocation属性指定mybatis的主配置文件 -->
    <property name="configLocation" value="classpath:spring/mybatis-config.xml" />
    <!-- 从类路径中加载映射文件,相对于类的根路径 -->
    <property name="mapperLocations" value="classpath:mapper/ja_zfcg/*.xml" />
    </bean>

    <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
    <constructor-arg ref="sqlSessionFactory" />
    </bean>
    <!-- DAO接口所在包名,Spring会自动查找其下的类 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.yzsoft.dao" />
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean> <bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dynamicDataSource" />
    </bean>
      

  2.   


    mybatis.jdbcDriver=oracle.jdbc.driver.OracleDriver
    mybatis.jdbcUrl=jdbc:oracle:thin:@127.0.0.1:1521:orcl
    mybatis.user=lw00
    mybatis.password=lw00
    mybatis.default_schema=lw00mybatis.initialSize=0  
    mybatis.maxActive=100  
    mybatis.maxIdle=30  
    mybatis.minIdle=5   
    mybatis.maxWait=5000  
    mybatis.removeAbandoned=true  
    mybatis.removeAbandonedTimeout=3000  
    mybatis.logAbandoned=false  
    mybatis.defaultAutoCommit=true  
    mybatis.defaultReadOnly=false  
    mybatis.validationQuery=SELECT 1  
    mybatis.testOnBorrow=true  
    mybatis.jdbcDriver1=oracle.jdbc.driver.OracleDriver
    mybatis.jdbcUrl1=jdbc:oracle:thin:@192.168.1.255:1521/orclyz
    mybatis.user1=lw01
    mybatis.password1=lw01mybatis.initialSize1=0  
    mybatis.maxActive1=100  
    mybatis.maxIdle1=30  
    mybatis.minIdle1=5   
    mybatis.maxWait1=5000  
    mybatis.removeAbandoned1=true  
    mybatis.removeAbandonedTimeout1=3000  
    mybatis.logAbandoned1=false  
    mybatis.defaultAutoCommit1=true  
    mybatis.defaultReadOnly1=false  
    #mybatis.minPoolSize1=3  
    #mybatis.maxPoolSize1=20  
    #mybatis.initialPoolSize1=5  
    #mybatis.maxIdleTime1=120   
    #mybatis.acquireIncrement1=5  
    #mybatis.maxStatements1=0  
    #mybatis.idleConnectionTestPeriod1=60  
    #mybatis.acquireRetryAttempts1=30  
    #mybatis.breakAfterAcquireFailure1=false  
    #mybatis.testConnectionOnCheckout1=false  
    #connection1.defaultAutoCommit=true  
    #connection1.defaultReadOnly=false
    #
    # <property name="minPoolSize1"><value>3</value></property>
    # <property name="maxPoolSize1"><value>20</value></property>
    # <property name="initialPoolSize1"><value>5</value></property>
    # <property name="maxIdleTime1"><value>120</value></property>
    # <property name="acquireIncrement1"><value>5</value></property>
    # <property name="maxStatements1"><value>0</value></property>
    # <property name="idleConnectionTestPeriod1"><value>60</value></property>
    # <property name="acquireRetryAttempts1"><value>30</value></property>
    # <property name="breakAfterAcquireFailure1"><value>false</value></property>
    # <property name="testConnectionOnCheckout1"><value>false</value></property>
      

  3.   

    应用所对应的主数据库配置可以用mybatis做持久化,额外的数据源,视具体情况再定了