日期:2014-05-20  浏览次数:20906 次

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("配置成功");