Issue
This is my class:
@Repository
@RequiredArgsConstructor
@Slf4j
public class ServeiTerritorialCatalegsClientRepositoryImpl implements ServeiTerritorialCatalegsClientRepository {
@Qualifier("catalegsMarshaller") private final Marshaller marshaller;
//...
}
My bean definition is:
@Bean
public Marshaller oidMarshaller() throws JAXBException {
//...
}
@Bean
public Marshaller catalegsMarshaller() throws JAXBException {
//...
}
I'm getting this message:
***************************
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
Solution
You will need to do two things:
Update lombok.config and add this -
lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Qualifier
Use @Qualifier and provide a suitable unique name. Ex:
@Repository @RequiredArgsConstructor @Slf4j public class MyImplClass{ @Qualifier("Myqualifier1") MyBean bean; Person getPerson() }
See lombok config guide here - lombokconfig
Answered By - Dinesh Arora