我是靠谱客的博主 俭朴红牛,最近开发中收集的这篇文章主要介绍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 SSM注解错误 HTTP Status 500 - Servlet.init() for servlet SpringMVC threw exception所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复