No qualifying bean of type [com.dao.UserDao] found for dependency:

「爱情、让人受尽委屈。」 2022-05-24 04:20 232阅读 0赞

唉。真的是醉了。被这个问题耽误了一天的时间,根据报错的提示,一直在在找错误,一直以为是注解错误,可是最后的错误却是mapper.xml 中的我把它写成了。。。。。还好是把错误找到了。。。。。真的是为自己的粗心付出了惨痛的代价。

这里把我找到的注解错误的解决办法整理一下,以防万一。

整体来说是,先看web.xml有没有写

contextConfigLocation

classpath:applicationContext-*.xml

org.springframework.web.context.ContextLoaderListener


springmvc
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
classpath:springmvc-config.xml

1

即是要在web.xml中加载applicationContext-*.xml和springmvc-config.xml 。classpath:代表根目录,我把配置文件放在了根目录了。

然后在看applicationContext-*.xml,


  1. </bean>

接着springmvc-config.xml,



  1. <context:component-scan base-package="com.ssm.service"/>

还有就是mapper.java和mapper.xml需要看一下是否映射正确,名字,方法名,namespace属性值格式。

发表评论

表情:
评论列表 (有 0 条评论,232人围观)

还没有评论,来说两句吧...

相关阅读