2016-12-14 74 views
0

我試圖在我的春天項目中使用mybatis,但我想知道一件事情:是applicationContext需要任何配置來讀取mybatis.xml?春天未能轉換mybatis配置

這裏是我的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。

回答

0

您配置的錯誤類型爲configuration財產,它不是一個Strting,你應該org.apache.ibatis.session.Configuration下面顯示了內部bean的配置吧:

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

看來你真的wnat爲config的configLocation財產。

+0

感謝。我使用'configLocation'而不是'configuration'並且它工作。 –

0

我發現問題在哪裏。

刪除此配置:

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

代替:

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