程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Springboot 依赖项:找到两个依赖项并忽略 Qualifier大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Springboot 依赖项:找到两个依赖项并忽略 Qualifier?

开发过程中遇到Springboot 依赖项:找到两个依赖项并忽略 Qualifier的问题如何解决?下面主要结合日常开发的经验,给出你关于Springboot 依赖项:找到两个依赖项并忽略 Qualifier的解决方法建议,希望对你解决Springboot 依赖项:找到两个依赖项并忽略 Qualifier有所启发或帮助;

这是我的课:

@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

解决方法

你需要做两件事:

  1. 更新 lombok.config 并添加这个 -

    lombok.copyableAnnotations += org.springframework.beans.factory.Annotation.Qualifier

  2. 使用@Qualifier 并提供一个合适的唯一名称。例如:

@Repository
@requiredArgsConstructor
@Slf4j
public class MyImplClass{
  @Qualifier("Myqualifier1") MyBean bean;
 
  Person getPerson()
}

在此处查看 lombok 配置指南 - lombokconfig

,

在 ServeiTerritorialCatalegsClientRepositoryImpl 类中,似乎有一个构造函数,其第三个参数是 Marshaller 类型。 因此,在构造函数中定义参数时,请为参数类型 Marshaller 使用限定符 ttribute,如下所示:

public ServeiTerritorialCatalegsClientRepositoryImpl(parameter1,paramter2,@Qualifier("catalegsmarshaller") Marshaller marshaller1)

,

Lombok 不会将注释从字段复制到构造函数参数或属性访问器。您现在需要自己提供构造函数。

大佬总结

以上是大佬教程为你收集整理的Springboot 依赖项:找到两个依赖项并忽略 Qualifier全部内容,希望文章能够帮你解决Springboot 依赖项:找到两个依赖项并忽略 Qualifier所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。