Spring - Error creating bean with name ‘XX‘: Unsatisfied dependency expressed through field ‘XX‘
Posted MinggeQingchun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring - Error creating bean with name ‘XX‘: Unsatisfied dependency expressed through field ‘XX‘相关的知识,希望对你有一定的参考价值。
在项目中经常会遇到如下错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'XX': Unsatisfied dependency expressed through field 'XX'
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 [xx\\mappers\\xxMapper.xml]';
报错:不满足依赖异常。创建名为’xx’的bean时出错,通过字段’sqlSessionFactory’表达的不满足的依赖项
一、配置与扫描问题:
spring配置文件中检查包是否扫描,仔细检查自己的配置文件里和相关的配置路径。
在项目配置文件(xxxConfig.class)中的配置:
private String[] locations = "classpath*:com/d1mgroup/wechat/estore/repository/*.xml";
在application.yml文件中的配置:
或者检查一下启动类上的注解配置:
二、注解问题:
Controller、service层的注解缺失会造成创建bean时出现错误
@Controller
@Service
三、依赖包缺失,检查pom配置文件
检查pom.xml文件下是否缺失依赖或者有多余的依赖,判断是否对bean的正常创建有影响
四、xml包中存在空文件:
在xxxMapper.xml的包中如果有空的xml文件,就会造成此Bug,这种情况的具体原因暂时不清楚
五、复制xml文件;文件名确实存在错误
以上都没解决问题,则直接备份一下mapper或者mapper.xml文件,将其删除,重新创建同名mapper或者mapper.xml文件,然后Maven clean 一下,重新Rebuild project
以上是关于Spring - Error creating bean with name ‘XX‘: Unsatisfied dependency expressed through field ‘XX‘的主要内容,如果未能解决你的问题,请参考以下文章
spring Error creating bean with name 'xxxx'
Spring 报错:Error creating bean with name
Error creating bean with name 'org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration
spring-boot导入redis依赖后报错 Error creating bean with name ‘redisConnectionFactory‘
spring boot maven install时报错 Error creating bean with name 'serverEndpointExporter'
Error creating bean with name 'org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration(示例代