![](/img/trans.png)
[英]spring+springmvc+mybatis:Injection of autowired dependencies failed
[英]spring failed to convert mybatis Configuration
我嘗試在春季項目中使用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嗎?
您為configuration
屬性配置了錯誤的類型,它不是Strting
,應使用org.apache.ibatis.session.Configuration
對其進行配置,如下所示在內部bean中:
<property name="configuration">
<bean class="org.apache.ibatis.session.Configuration">
....
</bean>
</property>
看來您真正擁有的是config configLocation
屬性。
我找到了問題所在。
刪除此配置:
<property name="configuration" value="classpath:mybatis/mybatis-config.xml" />
代替:
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.