控制台异常信息如下:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘xxxController’: Unsatisfied dependency expressed through field ‘xxxService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘xxxServiceImpl’: Unsatisfied dependency expressed through field ‘xxxDao’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.xxxx.dao.xxxx.xxxDao’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
详细解释
UnsatisfiedDependencyException:这个翻译后的意思是“不满足依赖异常”,可以看到前面“org.springframework.beans.factory”的这个信息,这个异常属于Spring的bean.factory的,就是说属于Spring的IOC容器里发生了这个异常,大家都知道IOC是管理对象的,这个异常的发生就说明你有类(Bean)没有放入到IOC中,那么它就无法创建所需要的对象,导致依赖创建失败。
NoSuchBeanDefinitionException:这个异常一般是有bean没有加入到容器中,从提示中也可以很清楚的看出是xxxDao没有加入到容器中。
解决方案
1.是否加了对应的注解(如Service、Dao)
2.注解包路径是否是正确的(我这里就是包路径导错了)