No qualifying bean of type 'XXXXX' available

简介: 该文档描述了Spring框架中`org.springframework.beans.factory.NoSuchBeanDefinitionException`异常的处理方法,该异常是因为无法找到类型为`com.weblog.auth.mapper.UserMapper`的bean导致。解决办法包括在对应的Mapper上添加`@Mapper`注解,并在启动类上添加`@MapperScan`注解以扫描包含Mapper接口的文件夹。
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'baseMapper': No qualifying bean of type 'com.weblog.auth.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.weblog.auth.mapper.UserMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

错误:org.springframework.beans.factory.NoSuchBeanDefinitionException。没有在factory找到已经定义的bean

解释:No qualifying bean of type 'XXXX' available。具体是哪一个没有找到,根据com.weblog.auth.mapper.UserMapper找到提示的包

引起原因:在使用自动注入的时候,没有找到对应的bean

image.png

解决方案:

  1. 在对应的Mapper上添加@Mapper注解

image.png

  1. 在启动类上添加@MapperScan注解,指定到mapper所在的文件夹(推荐)

image.png



目录
相关文章
|
Java 数据库连接 mybatis
Consider defining a bean of type ‘com.example.democrud.democurd.usermapper.DaoMapper‘ in your config
Consider defining a bean of type ‘com.example.democrud.democurd.usermapper.DaoMapper‘ in your config
214 0
|
4月前
Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationManager' in your configuration.
Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationManager' in your configuration.
117 0
|
5月前
|
XML 数据格式
Could not autowire. No beans of ‘VideoDao‘ type found.
Could not autowire. No beans of ‘VideoDao‘ type found.
|
7月前
No qualifying bean of type [com.XX.mapper.SysNameMapper ] found for dependency
No qualifying bean of type [com.XX.mapper.SysNameMapper ] found for dependency
100 0
|
Java Spring 容器
No qualifying bean of type ‘java.lang.String‘ available: expected at least 1 bean which qualifies
No qualifying bean of type ‘java.lang.String‘ available: expected at least 1 bean which qualifies
992 0
No qualifying bean of type ‘java.lang.String‘ available: expected at least 1 bean which qualifies
解决requried a bean of type xxx的问题(可能原因之一)
解决requried a bean of type xxx的问题(可能原因之一)
436 0
|
Java 容器 Spring
No qualifying bean of type或Unsatisfied dependency expressed through field ‘XXXService‘或@Autowired 注入
No qualifying bean of type或Unsatisfied dependency expressed through field ‘XXXService‘或@Autowired 注入
217 0
|
Java 编译器
解决NoSuchBeanDefinitionException: No qualifying bean of type ‘bean.User‘ available
解决NoSuchBeanDefinitionException: No qualifying bean of type ‘bean.User‘ available
202 0
|
Java Spring
required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.
required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.
required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.
|
NoSQL Java Redis
5. 成功解决:Could not autowire. No beans of 'RedisConnectionFactory' type found.
今天建了一个新项目,使用 Spring Boot 整合 Redis 时,IDEA 被提醒“Could not autowire. No beans of 'RedisConnectionFactory' type found. ”错误,意思是不能自动装配“RedisConnectionFactory”。
3267 1