現象: 在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的名字不能寫成其他的名字 應該寫成對應的接口的名字 
這樣就完成依賴注入了
新聞熱點
疑難解答