SSH整合时sessionFactory or hibernateTemplate is required异常

简介:
 

我们知道对继承了org.springframework.orm.hibernate3.support.HibernateDaoSupport的类来说,需要注入sessionFactory呢?因为spring在初始化容器的时候会对这个对象作一个check, 看下HibernateDaoSupport源码中的checkDaoConfig()方法 就清楚啦:

protected final void checkDaoConfig()
{      
    if (this.hibernateTemplate == null)
    {      
        throw new IllegalArgumentException
            ("'sessionFactory' or 'hibernateTemplate' is required");    
    }      

 

但是在spring配置文件中加入sessionFactory的bean配置以后,仍然出现异常。

后来看了网上的解决方式,原因是spring.xml中没有加上default- ,在注解的时候找不到实例化的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- default-lazy-init="true">

目录
相关文章
在使用SSH+Spring开发webservice ,报的一些异常及处理方法
在使用SSH+Spring开发webservice ,报的一些异常及处理方法
317 0
在使用SSH+Spring开发webservice ,报的一些异常及处理方法
|
10月前
|
监控 Ubuntu Linux
使用VSCode通过SSH远程登录阿里云Linux服务器异常崩溃
通过 VSCode 的 Remote - SSH 插件远程连接阿里云 Ubuntu 22 服务器时,会因高 CPU 使用率导致连接断开。经排查发现,VSCode 连接根目录 ".." 时会频繁调用"rg"(ripgrep)进行文件搜索,导致 CPU 负载过高。解决方法是将连接目录改为"root"(或其他具体的路径),避免不必要的文件检索,从而恢复正常连接。
|
网络安全
SNETCracker.exe 2022/1/26 31:13:29----检查12.26.20.1:SSH登录发生异常!未能加载文件或程序集“ChilkatDotNet4.dll”或它的某一个依赖项
SNETCracker.exe 2022/1/26 31:13:29----检查12.26.20.1:SSH登录发生异常!未能加载文件或程序集“ChilkatDotNet4.dll”或它的某一个依赖项
555 0
ssh2 Connection .connect()方法抛出连接过早关闭异常
ssh2 Connection .connect()方法抛出连接过早关闭异常
ssh2 Connection .connect()方法抛出连接过早关闭异常
|
关系型数据库 MySQL Java
|
Java 网络安全
SSH常见异常笔记(6)
SSH常见异常笔记(6)
141 0
|
开发框架 Oracle 关系型数据库
SSH常见异常笔记(5)
SSH常见异常笔记(5)
118 0
|
网络安全 数据库
SSH常见异常笔记(4)
SSH常见异常笔记(4)
139 0
|
网络安全
SSH常见异常笔记(3)
SSH常见异常笔记(3)
130 0
|
网络安全
SSH常见异常笔记(2)
SSH常见异常笔记(2)
141 0