gpt4 book ai didi

java - 创建了两个 conversionService bean

转载 作者:行者123 更新时间:2023-11-30 06:14:40 25 4
gpt4 key购买 nike

我在尝试升级我的应用程序时遇到错误

Description:

Field conversionService in com.profectus.dashboard.service.impl.DashBoardSettingsServiceimpl required a single bean, but 2 were found:
- mvcConversionService: defined by method 'mvcConversionService' in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]
- defaultConversionService: defined by method 'defaultConversionService' in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.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

为什么创建2个bean以及如何只保留一个转换器,我只想要能够将实体转换为pojo或将pojo转换为实体的spring core转换器。

我因为这个问题而陷入困境,任何线索都会有帮助。

服务类代码:-

import org.springframework.core.convert.ConversionService;
//other imports

@Service
public class DashBoardSettingsServiceimpl implements DashBoardSettingsService {

@Autowired
private DashBoardSettingJpaRepository dashBoardSettingRepo;

@Autowired
private ConversionService conversionService;

@Override
public DashBoardSettingResponse save(UserInfo userInfo, DashBoardSettingRequest request) {

//other coded
DashBoardSettigEntity entity = conversionService.convert(request.getDashBoardSetting(),
DashBoardSettigEntity.class);


DashBoardSettigEntity entityRetrieve = dashBoardSettingRepo.save(entity);

DashBoardSetting setting = conversionService.convert(entityRetrieve, DashBoardSetting.class);

DashBoardSettingResponse response = new DashBoardSettingResponse();

response.addDashBoardSetting(setting);
return response;
}
}

最佳答案

Autowiring 类型 DefaultConversionService 而不是 ConversionService

关于java - 创建了两个 conversionService bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49486717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com