Spring注入错误问题

现象:
在spring整合hibernate的时候 项目启动时出现异常
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘adaptrules’ defined in class path resource [spring/adaptrules-applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property ‘hibernateTemplate’ of bean class [com.adaptrules.task.AdaptrulesDaoImpl]: Bean property ‘hibernateTemplate’ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

这里写图片描述


原因之一:
在spring的容器向Action注入service的时候 不匹配的原因
这里写图片描述
如图 在bean容器里向adaptruleService 注入了id为adaptrules的Dao层 但是在adaptruleServiceImpl类中属性却写成的是AdaptrulesDao类的名称因此无法完成注入
这里写图片描述


解决办法:
在spring容器bean.xml文件注入的时候 id的名字不能写成其他的名字 应该写成对应的接口的名字
这里写图片描述

这样就完成依赖注入了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值