现象:
在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的名字不能写成其他的名字 应该写成对应的接口的名字
这样就完成依赖注入了