MyBatis整合Spring报错,希望大家给与帮助
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:Configuration.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
<constructor-arg index="1" value="BATCH" /><!--- 如果想要进行批量操作可加入这个属性 -->
</bean>
<bean id="empDaoImpl" class="dao.EmpDaoImpl">
<!--注入SqlSessionTemplate实例 -->
<property name="sqlSessionTemplate" ref="sqlSession" />
</bean>
java类:
public class EmpDaoImpl extends SqlSessionDaoSupport implements EmpDao{
....
}
报错如下:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unexpected failure during bean definition parsing
Offending resource: class path resource [spring.xml]
Bean 'empDaoImpl'; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: <property> element for property 'sqlSession' must specify a ref or value
Offending resource: class path resource [spring.xml]
Bean 'empDaoImpl'
-> Property 'sqlSession'
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:323)
貌似意思是说 sqlSession 需要指定一个引用 或者 指定一个值。 但是确实指定了。
java
spring
mybatis
------解决方案--------------------<bean id="empDaoImpl" class="dao.EmpDaoImpl">//这里的class是完整包名吗?
------解决方案--------------------可能类dao.EmpDaoImpl的属性是setSqlSession
<property name="
sqlSession" ref="sqlSession" />