spring无法转换mybatis配置

时间:2016-12-14 07:32:24

标签: xml spring mybatis

我尝试在我的spring项目中使用mybatis,但我想知道一件事:applicationContext是否需要任何配置来读取mybatis.xml?

这是我的xml:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="typeAliasesPackage" value="com.Ordering.Model" />
    <property name="mapperLocations" value="classpath:mapper/*.xml" />
</bean>

如果我添加此配置:

<property name="configuration" value="classpath:mybatis/mybatis-config.xml" />

我会收到这条消息:

Failed to convert property value of type 'java.lang.String' to required type 'org.apache.ibatis.session.Configuration'

当我删除它时,没有任何错误。我是否需要任何配置来转换mybatis.xml。

2 个答案:

答案 0 :(得分:0)

您为configuration属性配置了错误的类型,它不是Strting,您应该使用org.apache.ibatis.session.Configuration进行配置,如下面的内部bean所示:

  <property name="configuration">
    <bean class="org.apache.ibatis.session.Configuration">
      ....
    </bean>
  </property>

似乎你真正想要的是配置configLocation属性。

答案 1 :(得分:0)

我找到了问题所在。

删除此配置:

<property name="configuration" value="classpath:mybatis/mybatis-config.xml" />

而不是:

<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
相关问题