Spring整合MyBatis报UnsatisfiedDependencyException错误

记账:搭建Spring+SpringMvc+MyBatis框架上的两个小时智商税
报错如下:
HTTP Status 500 - Servlet.init() for servlet springmvc threw exception

type Exception report

message Servlet.init() for servlet springmvc threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet springmvc threw exception

root cause

org.springframework.beans.factory. UnsatisfiedDependencyException : Error creating bean with name ‘xxxxController’: Unsatisfied dependency expressed through field ‘xxxx’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.xxxx.service.impl.XxxXxxxxServiceImpl’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

大哥操着一嘴洋文,就是告诉咱,他没法 自动装配 啊,小弟我真是翻遍了度娘和Google,一顿排错, 终于!!!! 我找到错误了!是自己太粗心了!!!

问题位于web.xml

<!--添加前端控制器DispatcherServlet-->
    <!--加载Spring配置文件-->
    <listener>
        <listener-class>org.springframework.web.context.ContextCleanupListener</listener-class>
    </listener>

看到那个罪恶的 ContextCleanupListener 了吗!
没错!我手滑 点儿 错了!!!

<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

应该是 ContextLoaderListener

没错!他俩是org.springframework.web.context下的亲戚!(最气的就是他俩长得差不多!都是 “1大1” 的结构!!!)
不瞎扯了!来说说这俩亲戚都是干啥工作的吧!

ContextLoaderListener
监听器的作用:当启动web容器时。自动装配ApplicationContext.xml的配置信息

ContextCleanupListener
Web应用程序侦听器:用于清除ServletContext中剩余的可抛弃属性,即以前实现DisposableBean 但尚未删除的属性。

你可能感兴趣的:(Spring整合MyBatis报UnsatisfiedDependencyException错误)