MyBatis整合Spring报错,希望大家给与帮助

jackson_fighting 2013-03-25 11:50:18

<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 需要指定一个引用 或者 指定一个值。 但是确实指定了。
...全文
206 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
<bean id="empDaoImpl" class="dao.EmpDaoImpl">//这里的class是完整包名吗?
jackson_fighting 2013-03-25
  • 打赏
  • 举报
回复
请求大家给与支持!
jackson_fighting 2013-03-25
  • 打赏
  • 举报
回复
引用 6 楼 fangmingshijie 的回复:
看下版本,要3.1以上的spring才行
问题已经解决了,因为 Spring 与 mybatis 有多种整合方式,而Tomcat同时挂了3个项目跑,可能其中一个有问题。 谢谢您的回答
取名字好难 2013-03-25
  • 打赏
  • 举报
回复
你试试把接口配置进去,而不是配置实现类
jackson_fighting 2013-03-25
  • 打赏
  • 举报
回复
引用 6 楼 fangmingshijie 的回复:
看下版本,要3.1以上的spring才行
谢谢您的回答 mybatis是 3.1.1 spring 是 3.1.2
  • 打赏
  • 举报
回复
看下版本,要3.1以上的spring才行
jackson_fighting 2013-03-25
  • 打赏
  • 举报
回复
引用 3 楼 nanman 的回复:
可能类dao.EmpDaoImpl的属性是setSqlSession <property name="sqlSession" ref="sqlSession" />
谢谢您的回答 EmpDaoImpl extends SqlSessionDaoSupport 继承的是SqlSessionDaoSupport 这个类里面的属性是sqlSession 没错
jackson_fighting 2013-03-25
  • 打赏
  • 举报
回复
引用 2 楼 fangmingshijie 的回复:
<bean id="empDaoImpl" class="dao.EmpDaoImpl">//这里的class是完整包名吗?
谢谢您的回答,dao.EmpDaoImp 这个是完成的包名,按着ctrl点击也是能定位的
  • 打赏
  • 举报
回复
可能类dao.EmpDaoImpl的属性是setSqlSession <property name="sqlSession" ref="sqlSession" />

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧