java - Springboot 依赖:找到两个依赖并忽略限定符
问题描述
这是我的课:
@Repository
@RequiredArgsConstructor
@Slf4j
public class ServeiTerritorialCatalegsClientRepositoryImpl implements ServeiTerritorialCatalegsClientRepository {
@Qualifier("catalegsMarshaller") private final Marshaller marshaller;
//...
}
我的bean定义是:
@Bean
public Marshaller oidMarshaller() throws JAXBException {
//...
}
@Bean
public Marshaller catalegsMarshaller() throws JAXBException {
//...
}
我收到这条消息:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 3 of constructor in cat.catsalut.hes.mpi.hazelcast.loader.repository.ServeiTerritorialCatalegsClientRepositoryImpl required a single bean, but 2 were found:
- oidMarshaller: defined by method 'oidMarshaller' in class path resource [cat/catsalut/hes/mpi/hazelcast/loader/configuration/ServeiTerritorialConfiguration.class]
- catalegsMarshaller: defined by method 'catalegsMarshaller' in class path resource [cat/catsalut/hes/mpi/hazelcast/loader/configuration/ServeiTerritorialConfiguration.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
解决方案
你需要做两件事:
更新 lombok.config 并添加这个 -
lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Qualifier
使用 @Qualifier 并提供合适的唯一名称。前任:
@Repository @RequiredArgsConstructor @Slf4j public class MyImplClass{ @Qualifier("Myqualifier1") MyBean bean; Person getPerson() }
在此处查看 lombok 配置指南 - lombokconfig
推荐阅读
- javascript - 用 JS 创建的 SVG 路径不显示
- php - 如何访问管理面板 nova 只有超级管理员?
- mongodb - Mongodb总是增加“_id”字段?
- python - 迭代不可预测的 while 循环的时间复杂度是多少?
- java - Spark YARN 客户端模式(1 个主,4 个从):无法更改驱动程序内存。master的日志文件显示-Xmx1g
- r - R read.table 跳过参数跨平台不一致
- python - Pandas:如何根据 Z 值突出显示单元格值?
- sql - MariaDB中使用的字符串到整数的转换规则是什么
- vue.js - Vue 生产构建失败,在哪里寻找错误?
- api - 使用 Google Maps API 定义区域