当前位置: 代码迷 >> 综合 >> Field userService in XXX required a bean of type XXX that could not be found.
  详细解决方案

Field userService in XXX required a bean of type XXX that could not be found.

热度:38   发布时间:2024-02-13 05:20:06.0

1, 错误信息

Error starting ApplicationContext. To display the conditions report
re-run your application with ‘debug’ enabled.
141611.397-[ERROR]-[]-[main]-o.s.b.d.LoggingFailureAnalysisReporter:
*************************** APPLICATION FAILED TO START
*************************** Description: Field userService in XXX.rest.UserRest required a bean of type ‘XXX.service.UserService’
that could not be found.

The injection point has the following annotations:

  • @org.springframework.beans.factory.annotation.Autowired(required=true)

Action: Consider defining a bean of type
‘cn.exiaokang.g50k.service.UserService’ in your configuration.
Disconnected from the target VM, address: ‘127.0.0.1:64723’,
transport: ‘socket’ Process finished with exit code 1

在这里插入图片描述

2,解决方法
在启动类上加上@MapperScan或者@ComponentScan注解,手动指定application类要扫描哪些包下的注解

@ComponentScan(basePackages = {"com.xxx.xxx.dao"})

运行:
在这里插入图片描述

  相关解决方案