解决:Injection of autowired dependencies failed报错问题

解决如下报错:

Error creating bean with name ‘categoryManageController’: Injection of
autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private com.juhuasuan.service.IUserService
com.juhuasuan.controller.backend.CategoryManageController.iUserService;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘iUserService’: Injection of autowired
dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not
autowire field: private com.juhuasuan.dao.UserMapper
com.juhuasuan.service.Impl.UserServiceImpl.userMapper; nested
exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name ‘userMapper’ defined in file
[E:\neusoft\java\maven\maven_code\juhuasuan\target\classes\com\juhuasuan\dao\UserMapper.class]:
Unsatisfied dependency expressed through bean property
‘sqlSessionFactory’: : Error creating bean with name
‘sqlSessionFactory’ defined in class path resource
[applicationContext-datasource.xml]: Invocation of init method failed;
nested exception is org.springframework.core.NestedIOException: Failed
to parse mapping resource: ‘file
[E:\neusoft\java\maven\maven_code\juhuasuan\target\classes\mappers\CartMapper.xml]’;
nested exception is org.apache.ibatis.builder.BuilderException: Error
parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException:
Error resolving class. Cause: org.apache.ibatis.type.TypeException:
Could not resolve type alias ‘BaseResultMap’. Cause:
java.lang.ClassNotFoundException: Cannot find class: BaseResultMap;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘sqlSessionFactory’ defined in class path
resource [applicationContext-datasource.xml]: Invocation of init
method failed; nested exception is
org.springframework.core.NestedIOException:

在这里插入图片描述
遇到情况如下:
1.相关的bean已注册
2.所有的注解(@Controller,@Service,@Autowired)该加的地方都加上了
3.问题:自动装配的依赖注入失败,Injection of autowired dependencies failed

报错信息中的关键问题:(看报错信息要看全,要看到最后)
下面就是我在一堆报错信息中找到的核心问题

[E:\neusoft\java\maven\maven_code\juhuasuan\target\classes\mappers\CartMapper.xml]’;
Could not resolve type alias ‘BaseResultMap’. Cause:
java.lang.ClassNotFoundException: Cannot find class: BaseResultMap;

分析:在CartMapping.xml文件中无法解析别名为BaseResultMap,并且找不到该类,也就是说写了该类的地方出错,这里我是将结果集中resultMap写成resultType

错误的写法:
在这里插入图片描述
正确的写法:由于该方法返回结果集的是map,所以用的是resultMap
在这里插入图片描述
最后说说我对这个报错的理解:
自动装配的依赖注入失败

我是这样理解的,首先service依赖注入的是mapper文件,mapper文件的注解是@Autowired,所以mapper出错时,Autowired这个注解自然就不能自动装配到mapper文件中,所以就会出现报错Injection of autowired dependencies failed

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值