2016-12-14 73 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"/>