Field mapper in xxxServiceImpl required a single bean, but 5 were found:

目录

一、问题

二、解决方法


一、问题

重构代码时,遇到一个问题,写的基础实现类被多个类继承,下面按照错误提示修改一下

Field mapper in com.move.exam.app.service.base.BaseServiceImpl required a single bean, but 5 were found:
	- pageHelperProperties: defined by method 'pageHelperProperties' in class path resource [com/github/pagehelper/autoconfigure/PageHelperAutoConfiguration.class]
	- systemProperties: a programmatically registered singleton	- systemEnvironment: a programmatically registered singleton	- contextParameters: a programmatically registered singleton	- contextAttributes: a programmatically registered singleton

Action:

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



com中的字段映射器。移动考试应用程序。服务基础BaseServiceImpl需要一个bean,但找到了5个:

-pageHelperProperties:由类路径资源[com/github/pagehelper/autoconfigure/PageHelperAutoConfiguration.class]中的方法“pageHelperProperties”定义

-systemProperties:编程注册的singleton-systemEnvironment:编程注册的singleton-contextParameters:编程注册的singleton-contextAttributes:编程注册的singleton

行动:

考虑将其中一个bean标记为@Primary,

更新消费者以接受多个bean,

或者使用@Qualifier来标识应该使用的bean 

二、解决方法

给其中一个实现类添加@Primary标记为默认初始化的类即可

猜你喜欢

转载自blog.csdn.net/libusi001/article/details/124417676