首先遇到的问题就是HibernateDaoSupport引起的,程序中所有的DAO都继承自HibernateDaoSupport,而HibernateDaoSupport需要注入sessionfactory或者hibernateTemplate,所以出现"sessionFactory " or "hibernateTemplate " is required异常,但是在spring配置文件中加入sessionFactory的bean配置以后,仍然出现异常。
后来看了网上的解决方式 ,原因是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。
本站原创,转载请标明:来自蔡傑儒博客(http://www.cnblogs.com/cxy0703/)

SSH整合,"sessionFactory " or "hibernateTemplate " is required异常的更多相关文章

  1. "sessionFactory " or "hibernateTemplate " is required异常

    <beans    xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http:/ ...

  2. Hibernate整合Spring异常'sessionFactory' or 'hibernateTemplate' is required

    今日在写GenericDao时,发现了一个异常,内容如下: org.springframework.beans.factory.BeanCreationException: Error creatin ...

  3. SSH框架环境搭建问题:java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

    SSH框架启动tomcate时出错 严重: Exception sending context initialized event to listener instance of class org. ...

  4. spring注解方式,异常 'sessionFactory' or 'hibernateTemplate' is required的解决方法

    做单元测试的时候,抛出异常 Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' ...

  5. java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required

    java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required 严重: Exceptio ...

  6. 'sessionFactory' or 'hibernateTemplate' is required解决方法

    这种情况就是在通过spring配置hibernate4的时候(注意,这里是hibernate4不是hibernate3,hibernate3的),使用的是HibernateDaoSupport的这种方 ...

  7. 'sessionFactory' or 'hibernateTemplate' is required

    网上都是说在dao中未注入  sessionFactory,然而我有 于是排除 @Autowired public FlightDaoImpl(@Qualifier(value = "ses ...

  8. SSH整合常见错误

    spring+hibernate出错小结: (1)java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext ...

  9. 用ssh整合时,用sessionfactory的getCurrentSession()获取不到session

    在用ssh整合时,一开始用的是getCurrentSession(),获取当前线程上的session,但是总是抛异常,不能获取. 后来用sessionfactory的openSession(),但是, ...

随机推荐

  1. Java 多线程 socket 取款例子 runnable callable

    socket部分参考 http://blog.csdn.net/kongxx/article/details/7259465 取款部分参考 http://blog.csdn.net/dayday198 ...

  2. 读书笔记: 深入浅出node.js

    >> 深入浅出node.js node.js是c++编写的js运行环境 浏览器: 渲染引擎 + js引擎 后端的js运行环境 node.js用google v8引擎,同时提供很多系统级的A ...

  3. QSlider解决点击不能到该位置问题

    方法一:可以继承重写一个QSlider 方法二:1.instaneventfiliter(this);slider安装一个事件过滤器 2.在eventfilter(QObject *,QEvent*) ...

  4. android天气查询(二)之网络json数据的获取

    前面一篇文章介绍了如何使用ksoap获取天气信息,但是使用的网络资源受到了限制,所以我们这里会采用第二种方法,可以无限制的获取.http://m.weather.com.cn/data/1010101 ...

  5. D - 楼下水题(kmp+Manacher)

    D - 楼下水题 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Statu ...

  6. mysql 假设存在id则设数据自添加1 ,不存在则加入。java月份计算比較

    </pre><pre name="code" class="sql">INSERT INTO invite_rejectlog_num ...

  7. Windows 无法启动xx服务 错误1053:服务没有及时响应启动或控制请求

    症状:win7系统的很多系统关键服务,启动不了,双击该服务也弹不了操作框,系统服务是设置为自动 的,但是就是启动不了,在本地服务窗口中只能启动该服务,但是双击会弹不了窗口,你点启动后会出现错误提示10 ...

  8. ansible变量

    ansible变量 (部分内容摘自互联网,非官方,描述不一定正确) 变量种类: 内置变量facts: 自定义变量: 命令行传递的变量 roles传递的变量 主机变量 组变量 内置变量facts: 由远 ...

  9. leetcode 211. Add and Search Word - Data structure design Trie树

    题目链接 写一个数据结构, 支持两种操作. 加入一个字符串, 查找一个字符串是否存在.查找的时候, '.'可以代表任意一个字符. 显然是Trie树, 添加就是正常的添加, 查找的时候只要dfs查找就可 ...

  10. Oracle逐行累加求和

    最近遇到一个比较常见的问题,每行记录需要累加求和.这些问题倒不是有多难,主要是在工作的过程中会经常遇到,特别是Oracle自带的一些函数也能够很好地解决这样一些通用的查询计算,在此记录一下. 问题描述 ...