spring+hibernate整合问题

问题描述

一个继承hibernateDaoSupport的类UserDaoImpl.java如下:publicclassUserDaoImplextendsHibernateDaoSupportimplementsUserDao{publicvoidaddUser(UserBeanuser){/*Sessionsession=myUtilTools.getSession();session.beginTransaction();session.save(user);session.getTransaction().commit();myUtilTools.closeSession(session);*/System.out.println(user.getName());//能输出值。。System.out.println(this.getHibernateTemplate());//为NULL。this.getHibernateTemplate().save(user);}

applicationContext.xml配置如下:<!--配置sessionFactory--><beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="configLocation"><value>classpath:hibernate.cfg.xml</value></property></bean><!--配置事务管理器--><beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><propertyname="sessionFactory"ref="sessionFactory"/></bean><!--给用户服务类注入实现类--><beanid="UserDaoImpl"class="com.chengge.dao.impl.UserDaoImpl"><propertyname="sessionFactory"ref="sessionFactory"></property></bean>

Web.xml配置如下下:<filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list>

(问题:为什么this.getHibernateTemplate()的值为NULL。。郁闷中。。。)

解决方案

解决方案二:
该回复于2011-10-20 14:02:55被版主删除

时间: 2024-09-08 10:40:13

spring+hibernate整合问题的相关文章

Spring hibernate 整合报的错

问题描述 Spring hibernate 整合报的错 SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanCreationException: Error creating bean with name

struts2 spring hibernate整合后报错

问题描述 struts2 spring hibernate整合后报错 在eclipse里面run on server之后,可以正确显示界面,但当填写表单点击按钮后出现了这个报错 Struts Problem Report Struts has detected an unhandled exception: Messages: 1.org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session; 2.Method

Spring + Hibernate 整合,前辈们救救小弟 我不会吝啬分的

问题描述 这两天在学习这两个框架的整合,问题如下:Hibernate配置文件如下:<hibernate-configuration><session-factory><propertyname="connection.url">jdbc:sqlserver://localhost:1433;databaseName=ManagerDB</property><propertyname="connection.username

JSF Spring Hibernate整合:JSH1

JSF1.1 + Spring2.0 + Hibernate3.1 图示: JSF1.1 Jar包 : MyFaces1.1 Jar包: Spring与Hibernate包的配置与文章<SSH1基本配置(Struts1.2 + Spring2.0 + Hibernate3.1)>一致 地址: http://sunspot.blog.51cto.com/372554/468430

Spring HIbernate 整合问题

问题描述 测试出错,请大家帮我看看怎么回事:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'userService':Injectionofresourcemethodsfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'u

struts2 spring hibernate 整合错误?????

问题描述 严重:ExceptionstartingfilterstrutsUnabletoloadconfiguration.-action-file:/G:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/TestStruts26/WEB-INF/classes/struts.xml:11:43atorg.apache.struts2.dispatcher.Dispatcher.init(Dispatche

03SpringMVC,Spring,Hibernate整合(Date时间转换)

 项目结构 2 web.xml的配置内容如下: <?xmlversion="1.0"encoding="UTF-8"?> <web-appversion="2.5"xmlns="http://java.sun.com/xml/ns/javaee"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schema

struts2+spring+hibernate整合,spring出现问题.

问题描述 先看看我的配置文件:<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="

Struts Spring Hibernate整合:SSH1

Struts1.2 + Spring2.0 + Hibernate3.1 图示: Struts1.2 Jar包: Spring2.0 Jar包: Hibernate3.1 Jar包: 官方下载的 Hibernate3.1文件夹lib下的全部Jar包 其他必须包: