异常信息
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServImpl' defined in class path resource [spring/applicationContext-biz.xml]: Cannot resolve reference to bean 'userDaoImpl' while setting bean property 'iuserDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDaoImpl' defined in class path resource [spring/applicationContext-dao.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [com.tarena.dao.impl.UserDaoImpl]: Bean property 'sessionFactory' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?报错地点是我写的一个applicationContext-dao.xml
<bean id="userDaoImpl" class="com.tarena.dao.impl.UserDaoImpl">
<!-- 把下面这句注销就没事了 -->
<property name="sessionFactory" ref="sessionFactory" />
</bean>其中这个applicationContext-dao.xml被applicationContext.xml引用<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="dataSource" ref="dataSource"/>
   
   <!-- hiberante属性 -->
   <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    ${hibernate.dialect}
    </prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
    </props>
   </property>
   
   <!-- hiberante映射文件 -->
    <property name="mappingLocations">
     <list>
     <value>
     classpath:hibernate/hbm/User.hbm.xml
     </value>
     </list>
    </property>
</bean>




<!-- 配置声明事务管理 -->
<!-- 事务管理 -->

<!-- 定义事务规则(事务通知) -->

<!--定义方面完成织入-->

<!-- 引用其他spring配置文件 -->
     <import resource="applicationContext-web.xml"/>
     <import resource="applicationContext-biz.xml"/>
     <import resource="applicationContext-dao.xml"/>
</beans>
在我测试的的时候后要是把applicationContext-dao.xml中的
<property name="sessionFactory" ref="sessionFactory" />注销就OK了 
测试的类是
public class SpringTest {
private static Log log = LogFactory.getLog(SpringTest.class); public static void main(String[] args) {
ApplicationContext ac = new FileSystemXmlApplicationContext(
"classpath:spring/applicationContext.xml");
log.info("配置成功");
}}
这是怎么回事 我有点晕了 这个sessionFactory不是哪个hibernate用吗 是哪里错了求大神指点  谢谢
springsessionFactorybeansetter

解决方案 »

  1.   

    UserDAOImpl 没有 setSessionFactory()方法。
    可以让 UserDAOImpl extends JdbcDaoSupport
    或者 UserDAOImpl  extends HibernateDaoSupport,即可。
    然后通过 JdbcTempalte或HibernateTempalte来操作。
    如:
    class UserDAOImpl extends HibernateDaoSupport implements IUserDAO{
    private HibernateTemplate template;
     
     public void init(){
      template=getHibernateTemplate();
     }
    public void update(MyModel model) {//通过tempalte操作
      template.saveOrUpdate(model);//保存或update
     }
    }
     <!-- 配置dao -->//增加 init-method="init"
       <bean id="userDAO" class="cn.com.dao.impl.UserDAOImpl" init-method="init">
         <property name="seessionFactory" ref="sessionFactory"></property>
       </bean>
    //action的bean配置如下
     <bean id="userLogin" class="cn.com.action.UserAction" scope="prototype">
        <property name="userManager" ref="userManager"></property>
      </bean>
      

  2.   

    谢谢谢谢  就是这样的 我没有UserDAOImpl extends JdbcDaoSupport  我晕 怎么把这个忘了 多谢 我还以为是jar包的事情 因为我刚刚换了新的jar包 多谢大神