MyBatis XML和Spring配置

时间:2018-05-08 16:45:52

标签: spring mybatis

我正在使用mybatis映射器(XML)和弹簧配置。要运行sql的段,我设置了vendorPropertiesdatasourcesqlSessionFactory(包括databaseIdProvider)。此外,在映射器中提供了databaseId="oracle"。映射器在mybatis-config文件中配置。 当我运行该服务时,即使mapper名称空间和SQL片段id与名称匹配,我也会看到错误消息。

"Invalid bound statement (not found):"

映射器配置:

<select id="getNextId" resultType="java.lang.Integer" databaseId="db2"> SELECT NEXT VALUE FOR TBL1 FROM SYSIBM.SYSDUMMY1 </select> 
<select id="getNextId" resultType="java.lang.Integer" databaseId="Oracle"> SELECT TBL1.NEXTVAL FROM DUAL </select>

AppContext.xml:

<bean id="vendorProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
  <property name="properties"> 
    <props> 
      <prop key="DB2">db2</prop> 
      <prop key="Oracle">oracle</prop> 
      <prop key="H2">h2</prop> 
      <prop key="MySQL">mysql</prop> 
    </props> 
  </property> 
</bean> 
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache"> 
  <constructor-arg ref="sqlSessionFactory"/> 
</bean>

AppContext.xml也包含databaseIdProvider bean:

<bean id="databaseIdProvider" class="org.apache.ibatis.mapping.VendorDatabaseIdProvider"> 
  <property name="properties" ref="vendorProperties"/> 
</bean> 
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource"/> 
  <property name="configLocation" value="classpath:mappers/mybatis-config.xml"/>
  <property name="databaseIdProvider" ref="databaseIdProvider"/> 
</bean>

有人可以帮助确定我一直得到的原因&#34;无效的绑定声明(未找到)&#34;解析与getNextId相关的查询时出错?

0 个答案:

没有答案