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 {

点赞