Search code examples
javaspringibatis

How to wire SqlMapClientFactoryBean a dataSource in spring.xml config file


<bean id="myDataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
    <property name="url"
        value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8" />
    <property name="user" value="root" />
    <property name="password" value="" />
</bean>

<bean name="ibatis" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation" value="WEB-INF/SqlMapConfig.xml" />
    <property name="dataSource" value="myDataSource" />
</bean>

this config always wrong, says cannot convert myDataSource to a real datasource object.


Solution

  • myDataSource is a bean, so should be injected by reference using ref attribute, instead of value:

    <property name="dataSource" ref="myDataSource" />