首页 > 学院 > 开发设计 > 正文

Spring注入错误问题

2019-11-08 03:16:36
字体:
来源:转载
供稿:网友

现象: 在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的名字不能写成其他的名字 应该写成对应的接口的名字 这里写图片描述

这样就完成依赖注入了


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表