getHibernateTemplate().getSessionFactory().getCurrentSession();

解决方案 »

  1.   

      我按你的方法试过了,还是不行。
      同样是获取不到session
      

  2.   

    是没取道session
    但没看出来为什么.
      

  3.   

    java一块贴上来了,看着的眼有点 晕了,呵呵,xml,
      

  4.   

    我把所有的配置文件都给出来吧
    ------------applicationContext.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="datasource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"
    value="com.microsoft.jdbc.sqlserver.SQLServerDriver">
    </property>
    <property name="url"
    value="jdbc:microsoft:sqlserver://localhost:1433">
    </property>
    <property name="username" value="sa"></property>
    <property name="password" value="123456789zzh"></property>
    </bean>
    <bean id="hibernateInterceptor"
    class="org.springframework.orm.hibernate3.HibernateInterceptor">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="datasource" />
    </property>
    <property name="hibernateProperties">
    <props>
      <!-- 表示允许自动提交 -->
    <prop key="hibernate.connection.autocommit">true</prop>
    <!-- 显示sql语句 -->
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.SQLServerDialect
    </prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>zzh/mybbs/vo/User.hbm.xml</value></list></property></bean>
    <bean id="hibernateTemplate"
    class="org.springframework.orm.hibernate3.HibernateTemplate">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="userdao" class="zzh.mybbs.dao.UserDao" abstract="true">
    </bean>
    <bean id="userdaoimpl" class="zzh.mybbs.dao.impl.UserDaoImpl" parent="userdao">
    <property name="hibernateTemplate">
    <ref bean="hibernateTemplate"/>
    </property>
    </bean>
    <bean name="/jsp/user" class="zzh.mybbs.struts.action.UserAction">
    <property name="userdao">
    <ref bean="userdaoimpl"/>
    </property>
    </bean>
    </beans>------web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <filter>
    <filter-name>EncodingFilter</filter-name>
    <filter-class>
    zzh.mybbs.charsetFilter.EncodingFilter
    </filter-class>
    <init-param>
    <param-name>charset</param-name>
    <param-value>gbk</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>EncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter>
    <filter-name>opensession</filter-name>
    <filter-class>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>opensession</filter-name>
    <url-pattern>*.do</url-pattern>
    </filter-mapping>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/classes/applicationContext.xml
    </param-value>
    </context-param>
    <listener>
      <listener-class>
       org.springframework.web.context.ContextLoaderListener
      </listener-class>
     </listener>
    <servlet>
    <servlet-name>context</servlet-name>
    <servlet-class>
    org.springframework.web.context.ContextLoaderServlet
    </servlet-class>
    </servlet>
      <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>3</param-value>
        </init-param>
        <init-param>
          <param-name>detail</param-name>
          <param-value>3</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>-----------------struts-config.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
      <data-sources />
      <form-beans >
        <form-bean name="userForm" type="zzh.mybbs.struts.form.UserForm" />  </form-beans>  <global-exceptions />
      <global-forwards />
      <action-mappings >
        <action
          attribute="userForm"
          input="/jsp/errors.jsp"
          name="userForm"
          parameter="status"
          path="/jsp/user"
          scope="request"
          type="zzh.mybbs.struts.action.UserAction">
            <forward name="registersuccess" path="/jsp/index.jsp"></forward>
            <forward name="registerfailure" path="/jsp/register.jsp"></forward>
          </action>
      </action-mappings>  <controller
    processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
    </controller>
      <message-resources parameter="zzh.mybbs.struts.ApplicationResources" />
    <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
       <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml"/>
    </plug-in>
    </struts-config>其余的java程序就不用贴了。应该不会有错。
      

  5.   

    北京招聘 Java 开发的高级软件工程师    公司招聘 在北京长期工作发展的 Java 开发的高级软件工程师 以及 开发项目组长;      软件工程师4K以上待遇  高级软件工程师至少6K以上,根据能力上不封顶;    
      公司地点在 青云当代大厦 (联想桥附近)      因为需要扩大招聘渠道,所以在此发贴,在多个招聘网站也有公告,公司  属于外资企业(东方金鸟),符合条件请发简历到邮箱:  [email protected] ;      公司目前有C++  JAVA 和 .NET  三个方面开发团队,Java 团队主要负责  运营网站系统 开发,希望有中高级人才一起加盟,共同发展。      希望有机会能一起奋斗!共同成长! 
      

  6.   

    一块一块的看的眼花!~~
    那就是sessionFactory没初始话了,看下有没有成功的加入配置文件
      

  7.   

    你的测试类有问题吧?
    UserDaoImpl user=new UserDaoImpl();  ------这个有不是从spring中得到的对象,自己new出来的话那不是等于没有用spring?
      

  8.   

    UserDaoImpl user=new UserDaoImpl();  ------这个有不是从spring中得到的对象,自己new出来的话那不是等于没有用spring?
    IoC的机制你更本就不懂.
    UserDaoImpl 你应该是setter 进去或者后造函数传进去的..
      

  9.   

       那只是测试呀,连SESSION都获取不到,当然spring配置就有问题了嘛。