Spring在bean里配置上 <property name="sessionFactory" ref="sessionFactory"/> 就出错
org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'use...
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userEbi' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'userDao' while setting bean property 'userDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'sessionFactory' of bean class [cn.itcast.ssh.user.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?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
at 展开
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
at 展开
4个回答
展开全部
在你的cn.itcast.ssh.user.dao.impl.UserDaoImpl类中加上
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory){
this.sessionFactory = sessionFactory;
}
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory){
this.sessionFactory = sessionFactory;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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?
创建的bean,在类中,没有setter方法,还要getter方法,setter方法注入bean
创建的bean,在类中,没有setter方法,还要getter方法,setter方法注入bean
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
由于在初始化 MyBatis 时,jdbc.properties 文件还没被加载进来,dataSource 的属性值没有被替换,就开始构造 sqlSessionFactory 类,属性值就会加载失败,你的代码改为这个
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
就好了。
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
就好了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询