当前位置:网站首页>Field queryIndexFieldnameService in xxxImpl required a single bean, but 19 were found:
Field queryIndexFieldnameService in xxxImpl required a single bean, but 19 were found:
2022-06-11 20:56:00 【qq_21480329】
因为项目实际需求,即多个类实现同一个接口,不同策略走不同的Service实现类。
接口类代码:
public interface IQueryIndexFieldnameService {
Object queryIndexByFieldname(IndexDictionaryCoreDTO dto);
}
由于项目中,由于有10多个类同时实现该接口,在使用spring自动注入时,项目报错有多个实例而不能启动。
报错详细日志:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-06-04 22:04:05.001 ERROR 30773 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field queryIndexFieldnameService in com.otitan.forest.inspector.dm.service.impl.QueryIndexServiceImpl required a single bean, but 19 were found:
- featureForestryIndustryOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/FeatureForestryIndustryOverviewServiceImpl.class]
- forestGrassWetlandResource: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/ForestGrassWetlandResourceServiceImpl.class]
- forestLandClassifiedArea: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/ForestLandClassifiedAreaServiceImpl.class]
- forestryGrasslandPestControlOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/ForestryGrasslandPestControlOverviewServiceImpl.class]
- forestryIndustryOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/ForestryIndustryOverviewServiceImpl.class]
- landGreeningForestCultivationOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/LandGreeningForestCultivationOverviewServiceImpl.class]
- nationForestFarmSeedlingDevelopmentOverviewForest: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/NationForestFarmSeedlingDevelopmentOverviewForestServiceImpl.class]
- nationForestFarmSeedlingDevelopmentOverviewSeedling: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/NationForestFarmSeedlingDevelopmentOverviewSeedlingServiceImpl.class]
- nationForestFarmSeedlingDevelopmentOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/NationForestFarmSeedlingDevelopmentOverviewServiceImpl.class]
- nationReserveForestConstructionOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/NationReserveForestConstructionOverviewServiceImpl.class]
- naturalForestProtectionForesterOverviewForest: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/NaturalForestProtectionForesterOverviewForestServiceImpl.class]
- naturalForestProtectionForesterOverviewPerson: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/NaturalForestProtectionForesterOverviewPersonServiceImpl.class]
- naturalForestProtectionForesterOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/NaturalForestProtectionForesterOverviewServiceImpl.class]
- natureReserveOverviewDistribution: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/NatureReserveOverviewDistributionServiceImpl.class]
- natureReserveOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/NatureReserveOverviewServiceImpl.class]
- publicWelfareForestConstructionOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/PublicWelfareForestConstructionOverviewServiceImpl.class]
- worldNaturalHeritageWildlifeResourceOverviewPlace: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/WorldNaturalHeritageWildlifeResourceOverviewPlaceServiceImpl.class]
- worldNaturalHeritageWildlifeResourceOverview: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/WorldNaturalHeritageWildlifeResourceOverviewServiceImpl.class]
- worldNaturalHeritageWildlifeResourceOverviewSpecies: defined in file [/Users/carter/Desktop/firm/GzForestInspection/dynamic-monitor/target/classes/com/otitan/forest/inspector/dm/service/impl/WorldNaturalHeritageWildlifeResourceOverviewSpeciesServiceImpl.class]
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
Process finished with exit code 1
解决方案:
1.不要直接注入IQueryIndexFieldnameService,即不要使用如下注入代码
@Autowired
private IQueryIndexFieldnameService queryIndexFieldnameService;
2.使用如下注入代码
@Autowired
private ApplicationContext applicationContext;
或者
@Autowired
private BeanFactory beanFactory;
3.获取Bean实例调用
// 校验bean是否存在
if (!applicationContext.containsBean(dto.getTypeCode())) {
return null;
}
Object object = ((IQueryIndexFieldnameService)applicationContext.getBean(dto.getTypeCode())).queryIndexByFieldname(dto);
if (object == null) {
return null;
}
相关大数据学习demo地址:
https://github.com/carteryh/big-data
边栏推荐
- Lanqi technology joins in, and dragon dragon dragon community welcomes leading chip design manufacturers again
- Brain cell membrane equivalent neural network training code
- Work assessment of spectral analysis of Jilin University in March of the 22nd spring -00079
- [data visualization] use Apache superset to visualize Clickhouse data
- Date of SQL optimization_ Format() function
- Product information | Poe network card family makes a collective appearance, the perfect partner of machine vision!
- Black circle display implementation
- Usage methods and cases of PLSQL blocks, cursors, functions, stored procedures and triggers of Oracle Database
- [unity plug-in] shader keyword analysis tool shadercontrol
- Recompile kubeadm to solve the problem of certificate expiration in one year
猜你喜欢
![[game theory complete information static game] strategic game](/img/d2/743e8d14e4fb27cbe883d1df1bca27.jpg)
[game theory complete information static game] strategic game
![[nk] 牛客练习赛100 C 小红的删数字](/img/f1/a99600e1800c087aceb60a559dee39.png)
[nk] 牛客练习赛100 C 小红的删数字

应用场景:现场直播节目制作NDI技术中PoE网卡的广泛应用

Simulate Oracle lock waiting and manual unlocking

Final examination of theory and practice of socialism with Chinese characteristics 1

The official announced the launch of Alibaba's 2023 global school recruitment: Technical Posts account for more than 60%

Yintai department store and Taobao tmall jointly create a green fashion show to help "carbon neutrality"
![[file upload vulnerability 04] server side mime detection and bypass experiment (based on upload-labs-2 shooting range)](/img/b8/521ca4bb8931afab9a3a4d0b015125.jpg)
[file upload vulnerability 04] server side mime detection and bypass experiment (based on upload-labs-2 shooting range)

输入值“18-20000hz”错误,设置信息不完整,请选择单位

新品发布:国产单电口千兆网卡正式量产!
随机推荐
Final examination of theory and practice of socialism with Chinese characteristics 1
输入值“18-20000hz”错误,设置信息不完整,请选择单位
[data visualization] Apache superset 1.2.0 tutorial (III) - detailed explanation of chart functions
2022-2028 global and Chinese thermopile detector Market Status and future development trend
Explanation of each column output by explain statement
Solution to unlimited restart of desktop and file explorer
应用场景:现场直播节目制作NDI技术中PoE网卡的广泛应用
The secret of derating - don't challenge Datasheet
Ubantu1804 two opencv versions coexist
【博弈论-绪论】
vectorDrawable使用报错
Summary of C language programming knowledge points 01
Wechat applet Bluetooth development
Toolbar替换ActionBar后Title不显示
The input value "18-20000hz" is incorrect. The setting information is incomplete. Please select a company
My collection of scientific research websites
Simulate Oracle lock waiting and manual unlocking
Work assessment of spectral analysis of Jilin University in March of the 22nd spring -00079
修改本地微信小程序的AppID
Chrome V8 source code 48 The secret of weak type addition,'+'source code analysis