所有service都报required a single bean, but 2 were found 问题

小灰灰 2020-11-07 04:00 6611阅读 6赞

所有service都报required a single bean, but 2 were found 问题

这些service都只有一个实现接口
报错如下:

  1. Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  2. 2020-10-10 15:03:14.127 ERROR [restartedMain] [o.s.b.diagnostics.LoggingFailureAnalysisReporter] -
  3. ***************************
  4. APPLICATION FAILED TO START
  5. ***************************
  6. Description:
  7. Field messageService in com.sto.unify.app.jnv2.controller.biz.TaskCenter.TaskCenterController required a single bean, but 2 were found:
  8. - taskMessageServiceImpl: defined in file [/Users/zgz/IdeaProjects/sto-app-face/sto-app-face-jn/sto-app-face-jn-service/target/classes/com/sto/unify/app/jnv2/service/core/task/impl/TaskMessageServiceImpl.class]
  9. - taskMessageService: defined in file [/Users/zgz/IdeaProjects/sto-app-face/sto-app-face-jn/sto-app-face-jn-service/target/classes/com/sto/unify/app/jnv2/service/core/task/TaskMessageService.class]
  10. Action:
  11. Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

解决方法1.:你可以直接用@Primary 和@Qualifier 解决但是总不能把每一个service 都加一个注解吧。

看下我的service:
在这里插入图片描述
确实只有一个实现了他。

出现的原因:
在这里插入图片描述
是我的mapperScan 扫描的时候扫描到了所有的包,而不是单独的mapper的包。所以才报了这个错误,修改成下面就可以了。

  1. @MapperScan(basePackages = { "com.sto.unify.app.jnv2.mapper"})

为什么会造成这个原因的,可以评论下面讨论!

发表评论

表情:
评论列表 (有 0 条评论,6611人围观)

还没有评论,来说两句吧...

相关阅读