SSH整合,"sessionFactory " or "hibernateTemplate " is required异常
后来看了网上的解决方式 ,原因是spring.xml中没有加上default-autowire="byName" ,在注解的时候找不到实例化的sessionFactory,而注入了一个空的,在hibernate检查的时候就报那个错了。spring配置文件加入byName的方式注入bean后,就可以正确使用注解了
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName" default-lazy-init="true">
总的原因就是缺少了这句default-autowire="byName"。这个鸟问题困惑了一下午
开始在没添加default-autowire="byName"的时候,我添加了如下代码就可以,不过这个只是使得找到问题出现的原因,并不是解决的最终方法,最终解决方法还是添加了上面的一句到配置文件中。
import com.yhqxgl.dao.TDeptDao;
import com.yhqxgl.entity.TDept;
@Repository("tDeptDaoImpl")
@Transactional
public class TDeptDaoImpl extends HibernateDaoSupport implements TDeptDao {
public boolean add(TDept dept) {
this.getHibernateTemplate().save(dept);
return true;
}
@Autowired
public void setSessionFactoryOverride(SessionFactory sessionFactory)
{
super.setSessionFactory(sessionFactory);
}
}
相当sessionFactory还没注入到HibernateDaoSupport中,使得这里的this.getHibernateTemplate()=null。
SSH整合,"sessionFactory " or "hibernateTemplate " is required异常的更多相关文章
- "sessionFactory " or "hibernateTemplate " is required异常
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http:/ ...
- Hibernate整合Spring异常'sessionFactory' or 'hibernateTemplate' is required
今日在写GenericDao时,发现了一个异常,内容如下: org.springframework.beans.factory.BeanCreationException: Error creatin ...
- SSH框架环境搭建问题:java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
SSH框架启动tomcate时出错 严重: Exception sending context initialized event to listener instance of class org. ...
- spring注解方式,异常 'sessionFactory' or 'hibernateTemplate' is required的解决方法
做单元测试的时候,抛出异常 Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' ...
- java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required 严重: Exceptio ...
- 'sessionFactory' or 'hibernateTemplate' is required解决方法
这种情况就是在通过spring配置hibernate4的时候(注意,这里是hibernate4不是hibernate3,hibernate3的),使用的是HibernateDaoSupport的这种方 ...
- 'sessionFactory' or 'hibernateTemplate' is required
网上都是说在dao中未注入 sessionFactory,然而我有 于是排除 @Autowired public FlightDaoImpl(@Qualifier(value = "ses ...
- SSH整合常见错误
spring+hibernate出错小结: (1)java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext ...
- 用ssh整合时,用sessionfactory的getCurrentSession()获取不到session
在用ssh整合时,一开始用的是getCurrentSession(),获取当前线程上的session,但是总是抛异常,不能获取. 后来用sessionfactory的openSession(),但是, ...
随机推荐
- IPv6地址的ping、telnet等操作
最近在研究https协议是如何传输数据的,用wireshark抓包分析,发现客户机和google网站在传输数据时使用了IPv6地址,于是相对ipv6地址测试下基本的功能. ping功能,直接使用pin ...
- ajaxFileUpload用法
首先要引入两个js <script type="text/javascript" src="/static/js/jquery.js"></s ...
- MVC-07 案例1
>>>>>ContosoUniversity网站 ------------------------------------------- 一.并发冲突 1. 为什么会并发 ...
- Delphi 的动态数组
传统的Pascal 语言其数组大小是预先确定的,当你用数组结构声明数据类型时,你必须指定数组元素的个数.专业程序员也许知道些许动态数组的实现技术,一般是采用指针,用手工分配并释放所需的内存. Delp ...
- 将dll放进exe[.Net]
原文:将dll放进exe[.Net] 两种方案: 1.使用ILMerge工具. 缺点:需离开工程,使用第三方工具(ILMerge). 2.将dll作为Resource放进exe,exe执行时动态加载( ...
- 利用bind搭建dns
下载bind,我下载的是bind-9.3.1rc1.tar.gz 我下载的文件放在/root目录下 进入目录解压缩 [root@linux root]#tar xfz bind-9.3.1rc1.ta ...
- JAVA GUI学习 - JTable表格组件学习_A ***
public class JTableKnow_A extends JFrame { public JTableKnow_A() { this.setBounds(300, 100, 400, 300 ...
- debian安装vld来查看Opcode,PHP调优。
一: 我的环境: Debian 7 (wheezy) x64 PHP 5.4.4-14 (apt-get 而来) Apache/2.2.22 (同上,非源码编译) 二 :安装vld. (# 代表是r ...
- iOS --- [持续更新中] iOS移动开发中的优质资源
在我们做iOS APP的开发过程中, 须要非常多设计, 产品, 技术, 运营等方面的技巧和资源. 现将其整理汇总, 本文会一直持续更新. 敬请关注. 设计 Dribbble Dribbble是一个面向 ...
- CSS3线性渐变linear-gradient
转自 http://www.w3cplus.com/content/css3-gradient CSS3的线性渐变 一.线性渐变在Mozilla下的应用 -moz-linear-gradient( [ ...