Servlet.init() for servlet dispatcher threw exception

关于在测试SSM项目的时候报错Servlet.init() for servlet [spring-dispatcher] threw exception的解决办法

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private cn.itsource.service.IDepartmentService cn.itsource.controller.DepartmentController.departmentService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.itsource.service.IDepartmentService] 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)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
	... 36 more
```![在这里插入图片描述](https://img-blog.csdnimg.cn/2019062409504415.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDYzNTc3OA==,size_16,color_FFFFFF,t_70)
#### 1,你肯定是在写完controller层之前开始出问题,而且在此之前你的这个SSM项目和前端的 还没有衔接好,所以你可以先把配置前端控制器的那部分先给注解掉,先不配置前端控制器,也就是下面这段代码![在这里插入图片描述](https://img-blog.csdnimg.cn/2019062409531884.png?x-oss-process=image/watermark,type_ZmFuZ3po

> 这里是引用

ZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDYzNTc3OA==,size_16,color_FFFFFF,t_70)
### 2,要么就是你把前端的静态资源代码先不要放到WEB-INF下面,直接放到WEB-INF外面的目录下
### 再或者就是你把整个三层controller,service,dao层完全做好,和前台的衔接也做好,就能解决问题了

我的是出现在第一个问题,写前思考层级结构,避免这种低级错误















你可能感兴趣的:(JAVA)