是直接测试还是用在WEB里测试啊>

解决方案 »

  1.   


    在你的web.xml文件中有没有配置SPRING
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param> <filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
    <init-param>
    <param-name>singleSession</param-name>
    <param-value>false</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>hibernateFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
      

  2.   

    spring配置hibernateTemplate时候用
    <property name="sessionFactory">
     <ref bean="sessionFactory" />
    </property>
    试试
      

  3.   

    你的spring 文件里面的sessionfactory配置肯定有问题.得不到数据库的连接
      

  4.   

        <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> 
            <constructor-arg> 
              <ref local="sessionFactory" /> 
            </constructor-arg> 
        </bean> 
    去掉!
      

  5.   

    web.xml加上<filter>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <filter-class>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
    </filter>
      

  6.   

    web.xml加上<filter>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <filter-class>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
    </filter>
      

  7.   

    应该 把 hibernateTemplate注入到你的UserDaoImpl里面,
    而不是sessionFactory注入 UserDaoImpl。