天天看點

org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***'



錯誤如下:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.zhym.service.NewsService]: Specified class is an interface

Caused by:

org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.zhym.service.NewsService]: Specified class is an interface

錯誤原因:首先確定service接口的實作類沒有錯,然後檢視applicationContext.xml中對此service的聲明,是否把bean中class後的包名中的service實作了寫成了service接口。比如service接口名:UserService.java,其實作類為UserServiceImpl.java,而你的bean寫成了<bean name="userService" class="com.zyy.service.UserService><!--省略中。。。--></bean>,這裡隻需把class改為:class="com.zyy.service.UserServiceImpl"

繼續閱讀