No qualifying bean of type 'com.frankxulei.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate

简介: Java Spring MVC 5 使用MyBatis连接池异常: 错误信息:No qualifying bean of type 'com.frankxulei.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate.

Java Spring MVC 5 使用MyBatis连接池异常:
错误信息:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.frankxulei.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1501)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1099)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1060)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:809)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:715)
... 45 more

原因分析:
控制器里使用了Autowired依赖注入,但是没有找到 依赖'com.frankxulei.service.UserService' 。
这里是代码:
public class UsersController {

@Autowired
private UserService userService;

解决办法:
依赖上加入名称即可,或者修改XML也行。
@Service("userService")
public class UserService {

目录
相关文章
|
10月前
|
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
109 0
|
Java Maven
MapStruct - Couldn‘t retrieve @Mapper annotation
MapStruct - Couldn‘t retrieve @Mapper annotation
1867 0
|
NoSQL Redis
Consider defining a bean of type ‘com.bsj.system.service.RedisService‘ in your configuration
Consider defining a bean of type ‘com.bsj.system.service.RedisService‘ in your configuration
440 0
|
6月前
|
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 注入
39 0
|
7月前
|
Java 编译器
解决NoSuchBeanDefinitionException: No qualifying bean of type ‘bean.User‘ available
解决NoSuchBeanDefinitionException: No qualifying bean of type ‘bean.User‘ available
记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration...
记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration...
237 0
|
11月前
|
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”。
2241 1
|
11月前
|
Java
springboot3 解决:Could not autowire. No beans of ‘JavaMailSender‘ type found
因为 spring-boot-starter-mail 默认使用某些包发生了变化,在 2.2.xx 版本前后不一,解决对应bug
291 0
|
11月前
|
druid
A bean with that name has already been defined in class path resource and overriding is disabled.
A bean with that name has already been defined in class path resource and overriding is disabled.
155 0
|
Java 编译器
Could not autowire. No beans of ‘RedisConnectionFactory‘ type found.已解决
在创建redisTemplate时,形参列表爆出了如下错误
845 0
Could not autowire. No beans of ‘RedisConnectionFactory‘ type found.已解决