日期:2014-05-18  浏览次数:20656 次

关于spring4与hibernate4注入问题,求大神!!!!!!!
spring配置如下
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  <property name="config" value="classpath:hibernate.cfg.xml"/>
</bean>

<bean id="userDao" class="com.ssh.dao.UserDao">
  <property name="sessionFactory" ref="sessionFactory"/>
</bean>

UserDao类中也有sessionFactory的setter和getter

测试方法:
BeanFactory beanFactory=new ClassPathXmlApplicationContext("beans.xml");
UserDao userDao=beanFactory.getBean("userDao", UserDao.class);
System.out.println(userDao.select("jack", "123"));

报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'config' of bean class [org.springframework.orm.hibernate4.LocalSessionFactoryBean]: Bean property 'config' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

这是什么问题,还请大神告知!!

------解决方案--------------------
<property name="configLocation" value="classpath:hibernate.cfg.xml" />  
------解决方案--------------------
引用:
最后一个问题:
<property name="configLocation" value="classpath:hibernate.cfg.xml" /> 
与c3p0,DBCP 哪种用的多些?
dbcp已经不怎么更新了,c3po用的多。