[报错解决](Error Creating bean with name ‘xxx‘)类问题解决思路

2年前 (2022) 程序员胖胖胖虎阿
276 0 0

遇到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)中的配置:

[报错解决](Error Creating bean with name ‘xxx‘)类问题解决思路

在application.yml文件中的配置:

[报错解决](Error Creating bean with name ‘xxx‘)类问题解决思路

或者检查一下启动类上的注解配置:

[报错解决](Error Creating bean with name ‘xxx‘)类问题解决思路

二、注解问题:

Controller、service层的注解缺失会造成创建bean时出现错误。

@Controller

@Service

三、依赖包缺失,检查pom配置文件

检查pom.xml文件下是否缺失依赖或者有多余的依赖,判断是否对bean的正常创建有影响。

四、xml包中存在空文件:

[报错解决](Error Creating bean with name ‘xxx‘)类问题解决思路

在xxxMapper.xml的包中如果有空的xml文件,就会造成此Bug,这种情况的具体原因暂时不清楚。

相关文章

暂无评论

暂无评论...