【发布时间】:2021-09-23 11:49:27
【问题描述】:
这是我的课:
@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
【问题讨论】:
-
我认为这是由于 RequiredArgsConstructor 注释。因为 Lombok 没有在构造函数中添加该 Qualifier 注释。
标签: java spring spring-boot lombok