我是靠谱客的博主 俭朴红牛,这篇文章主要介绍Java SSM注解错误 HTTP Status 500 - Servlet.init() for servlet SpringMVC threw exception,现在分享给大家,希望可以做个参考。


学习的道路是漫长滴,错误也是天天有的,有搞了我3天。废话少说,先上错误:

HTTP Status 500 - Servlet.init() for servlet SpringMVC threw exception
....(此处省略上上重点错误,如下:)
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.service.UserService com.controller.UserController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

看了很多资料说是业务侧没有注解:@Service,看了一下代码有啊,(若是没有注解也会报这种错误)



有的说控制层没有注解:
@Autowired
UserService userService ;



但是我也加了,为什么还是有错误呢,要是不用注解的方式,直接调用接口就没有错误(看注释)。
错误是莫名其妙的,但是还得找,代码看了几十遍还是没找到。
最后看到外国的一个论坛貌似理清楚了我的思路:spring-mvc.xml配置文件中也有配置自动扫描注解的代码: < context :component-scan base-package ="com.controller" />
最好发现配置文件的中注解代码是有的但是base-package的内容不对,看如下结构目录和配置:


最后贡献一下那个国外的论坛和<context:component-scan/>的介绍:
http://stackoverflow.com/questions/32493906/error-creating-bean-with-name-reportscontroller-injection-of-autowired-depend

http://blog.csdn.net/chunqiuwei/article/details/16115135





















最后

以上就是俭朴红牛最近收集整理的关于Java SSM注解错误 HTTP Status 500 - Servlet.init() for servlet SpringMVC threw exception的全部内容,更多相关Java内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部