问题描述
一个继承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被版主删除