java代码:public class InStorageRecordDaoImpl extends HibernateDaoSupport implements InStorageRecordDao {
private HibernateTemplate hibernatetemp; public void addInStorage(InStorageRecords isr) throws DaoException {
// TODO Auto-generated method stub
//添加入库单
getHibernateTemplate().save(isr); } public List<?> findAll() throws DaoException {
// TODO Auto-generated method stub
//查询所有的入库单
List<?> list=getHibernateTemplate().find("from InStorageRecords");

return list;
}
<!-- 配置事务管理器 --> <bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionfactory" />
</property>
</bean> <!-- 配置DAO --> <bean id="InStorageDao" class="com.hsh.hhoa.dao.impl.InStorageRecordDaoImpl">
<property name="hibernatetemp">
<ref bean="hibernateTemplate" />
</property>
</bean>
<!-- 配置service -->
<bean id="InStorageRecordsService" class="com.hsh.hhoa.service.impl.InStorageRecordsServiceImpl">
<property name="isrDao">
<ref bean="InStorageDao" />
</property>
</bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionfactory" />
</property>
</bean> <!-- 配置事务 -->
<bean id="instore"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="txManager" />
</property>
<property name="target">
<ref bean="InStorageRecordsService" />
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean> Error creating bean with name 'InStorageDao' defined in ServletContext resource [/WEB-INF/applicationcontxt/applicationContext_all.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required报这个异常 但我找不出 求高人指点

解决方案 »

  1.   

        <!-- 配置DAO -->    <bean id="InStorageDao" class="com.hsh.hhoa.dao.impl.InStorageRecordDaoImpl">
            <property name="hibernatetemp">
                <ref bean="hibernateTemplate" />
            </property>
        </bean>这个InStorageDao里面什么都别配置!
      

  2.   

    InStorageRecordDaoImpl里面的private HibernateTemplate hibernatetemp;不用写,在配置文件时候写成
     <bean id="InStorageDao" class="com.hsh.hhoa.dao.impl.InStorageRecordDaoImpl">
      <property name="hibernateTemplate">
      <ref bean="hibernateTemplate" />
      </property>
      </bean>
      

  3.   

    因为你extends HibernateDaoSupport所以直接可以  getHibernateTemplate() 获取实例
    不需要再定义private HibernateTemplate hibernatetemp;
    XML 里面的
    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
            <property name="sessionFactory">
                <ref bean="sessionfactory" />
            </property>
        </bean>
    删掉  <bean id="InStorageDao" class="com.hsh.hhoa.dao.impl.InStorageRecordDaoImpl">
            <property name="hibernatetemp">
                <ref bean="hibernateTemplate" />
            </property>
        </bean>
    改为  <bean id="InStorageDao" class="com.hsh.hhoa.dao.impl.InStorageRecordDaoImpl">
            <property name="sessionfactory">
                <ref bean="sessionfactory" />
            </property>
        </bean>
      

  4.   

    楼上正解  !    使用Hibernate 的时候  , 数据层的实现类继承了HibernateDaoSupport    并不需要在实现类中把hibernateTemplate  属性注入  
    只需要在配置中把sessionFactory 注入就可以啦     sessionFactory  是HibernateDaoSupport类的一个属性, 使用的时候使用this.getHibernateTemplate() 就可以啦 前提是spring 管理的容器中要有sessionFactory