遇到Error Creating bean with name ’ '这类问题的解决思路
错误日志关键部分:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productHandler': Unsatisfied dependency expressed through field 'productMapper'; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'xxxMapper' defined in file [xxxMapper.class]: 
Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sqlSessionFactoryBean' defined in class path resource [xxxConfig.class]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [xxx\mappers\testMapper.xml]'; 
nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 文件提前结束。
大意如下:不满足依赖异常。创建名为’xxxMapper’的bean时出错:通过字段’sqlSessionFactory’表达的不满足的依赖项;
一、配置与扫描问题:
spring配置文件中检查包是否扫描,仔细检查自己的配置文件里和相关的配置路径。
在项目配置文件(xxxConfig.class)中的配置:
![]()
在application.yml文件中的配置:
类问题解决思路插图1 [报错解决](Error Creating bean with name ‘xxx‘)类问题解决思路](https://pic.hicxy.com/2022/08/30400c98f21fd426513baee4dc7641553b.png)
或者检查一下启动类上的注解配置:
![]()
二、注解问题:
Controller、service层的注解缺失会造成创建bean时出现错误。
@Controller
@Service
三、依赖包缺失,检查pom配置文件
检查pom.xml文件下是否缺失依赖或者有多余的依赖,判断是否对bean的正常创建有影响。
四、xml包中存在空文件:
在xxxMapper.xml的包中如果有空的xml文件,就会造成此Bug,这种情况的具体原因暂时不清楚。
 
                    版权声明:程序员胖胖胖虎阿 发表于 2022年10月25日 上午9:08。
转载请注明:[报错解决](Error Creating bean with name ‘xxx‘)类问题解决思路 | 胖虎的工具箱-编程导航
                    
            转载请注明:[报错解决](Error Creating bean with name ‘xxx‘)类问题解决思路 | 胖虎的工具箱-编程导航
相关文章
暂无评论...

类问题解决思路插图3 [报错解决](Error Creating bean with name ‘xxx‘)类问题解决思路](https://pic.hicxy.com/2022/08/30e119af7951bf47310f7023a1421714a6.png)