首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

sessionFactory is not writable 错误

2013-09-11 
sessionFactory is not writable 异常异常信息Exception in thread main org.springframework.beans.fac

sessionFactory is not writable 异常
异常信息
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用吗 是哪里错了求大神指点  谢谢
spring sessionFactory bean setter
[解决办法]
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>

热点排行