## 关于org.springframework.beans.factory.BeanCreationException出现此问题的解决方法

关于org.springframework.beans.factory.BeanCreationException出现此问题的解决方法

ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘articleController’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘articleServiceImpl’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘articleMapper’ defined in file [D:\Workspaces\biyesheji\projectmis\target\classes\com\yxw\projectmis\mapper\ArticleMapper.class]: Unsatisfied dependency expressed through bean property ‘sqlSessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ‘sqlSessionFactory’ threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [D:\Workspaces\biyesheji\projectmis\target\classes\com\yxw\projectmis\mapper\ArticleMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is ‘file [D:\Workspaces\biyesheji\projectmis\target\classes\com\yxw\projectmis\mapper\ArticleMapper.xml]’. *
Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.yxw.projectmis.mapper.ArticleMapper.BaseResultMap*
2019-04-25 22:46:43.006 INFO 6676 — [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-04-25 22:46:43.052 INFO 6676 — [ main] ConditionEvaluationReportLoggingListener :

由以上的错误的代码可以看到,我们出现此类bug的原因:找到不到对应的bean,bean注入失败。

注入失败的原因主要有:
1.没有添加注解。例如:@Service @Autowared @Controller
2.错误的注入方法
3.对于web.xml中监听器的xml配置错误。
4.如果你以上三种方法都确认无误了 不妨去看看你mapper.xml是不是有问题,比如用mybaties逆向工程生成mapper.xml时是不是手抖运行了两遍或者两遍以上。如果是,你的mapper.xml中的方法会重复,注入时也会失败。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值