关于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中的方法会重复,注入时也会失败。