java吧 关注:1,244,298贴子:12,720,343
  • 8回复贴,共1

我junit测试spring+mybatis的整合,但是mapp老是注入失败,

只看楼主收藏回复

第一步:我的web.xml用通配符加载了所有的配置文件
第二步:配置好连接数据库需要的参数

第三步:配置基本的application.xml.导入连接数据库参数和扫描service包

第四步:配置扫描mapper和mapper.xml

第五步:以下是service、service,impl、mapper、mapper.xml




第六步:我的test类

第七步:我报错的内容
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'luoxu.UserTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.lx.service.UserService luoxu.UserTest.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lx.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)}
第八步:我感觉就是mapper一直注入不成功,我也是在学习搭建ssh框架,所以确实找不到问题在哪儿了,麻烦大家帮我看看,非常感谢,都纠结2两天了。


1楼2017-06-14 18:02回复
    UserServiceImpl类的限定名被你注解了,不是默认的,所以这里直接自动注入无法实例化


    2楼2017-06-14 18:43
    收起回复
      UserServiceImpl类的@service注解,你可以把后面的括号去掉,或者是把括号的内容换成类名首字母小写,问题就解决了


      3楼2017-06-14 19:58
      回复
        改了,还是不行的


        来自iPhone客户端4楼2017-06-14 20:00
        收起回复
          回复 Keep__Running :哈哈,写代码有时候出的问题真的是做梦都想不到


          来自iPhone客户端5楼2017-06-15 09:36
          回复