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,看了一下代码有啊,(若是没有注解也会报这种错误)

Java SSM注解错误 HTTP Status 500 - Servlet.init() for servlet SpringMVC threw exception_第1张图片

有的说控制层没有注解:
@Autowired
UserService userService ;
Java SSM注解错误 HTTP Status 500 - Servlet.init() for servlet SpringMVC threw exception_第2张图片


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

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

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





















你可能感兴趣的:(java,idea,spring,mvc,maven,tomcat,java)