需要帮助替换弃用的SqlMapClientFactoryBean

时间:2017-11-20 13:30:14

标签: database spring spring-data deprecated ibatis

我需要替换在新的Spring Boot项目中使用的这个已弃用的类。

  

的SqlMapClientFactoryBean

经过一番搜索,我找不到任何简单的方法来取代它,但我觉得必须有类似的选择吗?

请参阅豆类&个XML:

Bean定义:

<bean id="clientMap" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="dataSource" ref="datasource" />
    <property name="configLocation" value="classpath:/my/path/to/SqlMapConfig.xml" />
</bean>

SQLMapConfig.xml:

<sqlMapConfig>
   <settings cacheModelsEnabled="true"
             enhancementEnabled="true"
             lazyLoadingEnabled="false"
             maxRequests="32"
             maxSessions="10"
             maxTransactions="5"
             useStatementNamespaces="true"/>
   <sqlMap resource="path/to/config/ibatis/ibatis.xml"/>
</sqlMapConfig>

ibatis.xml:

<sqlMap namespace="abd.xyz.flow">
    <!-- Object-Index -->
    <resultMap id="objectIndexResult" class="abd.xyz.model.ObjectIndex">
        <result property="objectIndex" columnIndex="1" />
        <result property="idx1" columnIndex="2" />
        <result property="idx2" columnIndex="3" />
        <result property="idx3" columnIndex="4" />
        <result property="idx4" columnIndex="5" />      
    </resultMap>

    <select id="wflow.getObjectIndexById" resultMap="objectIndexResult">
        select * from om.object_index oi where oi.object_index = #objectIndex#
    </select>

    <!-- GPQ -->
    <resultMap id="detail" class="abc.xyz.model.SomeDetail">
        <result property="processId" column="PROCESS_ID" />
        <result property="processTypeDescr" column="PROCESS_TYPE_DESCR" />
        <result property="nextActionCd" column="NEXT_ACTION_CD" />
        <result property="idx9" column="IDX9" />
        <result property="idx17" column="IDX17" />
    </resultMap>

    <select id="flow.getDetails" resultMap="Detail">
        SELECT * FROM flow.detail
    </select>
</sqlMap>

提前致谢:)

1 个答案:

答案 0 :(得分:1)

看起来你是对的,文档可能无法如此清楚地解释这一点。看看官方Spring Boot MyBatis Examples。 您不需要一个班级来将SqlMapClientFactoryBean替换为另一个班级。

相当于替换datasource中的SqlMapClientFactoryBean

您应该只需在Spring Boot application.properties like so中声明数据源:

spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

相当于替换configLocation中的SqlMapClientFactoryBean

然后在application.properties文件中指定mybatis-config.xml location

mybatis.config-location=classpath:mybatis-config.xml

以上结论是您的问题;即相当于SqlMapClientFactoryBean

对于配置迁移的其余部分,mapper XML项目现在替换XML中的旧sqlMap settings docs indicate in your声明config file应保持大致相同。