Spring boot 使用JHipster注册表(云配置服务器作为中央服务器)集中微服务时,Bean定义覆盖异常

Spring boot 使用JHipster注册表(云配置服务器作为中央服务器)集中微服务时,Bean定义覆盖异常,spring-boot,jhipster,jhipster-registry,jhipster-gateway,Spring Boot,Jhipster,Jhipster Registry,Jhipster Gateway,在JHipster注册表中集中micro service客户端配置的过程中,我目前面临一个问题。我正在使用文件系统方法来集中注册表应用程序的配置(中央配置)文件夹 在运行时启动micro service客户端应用程序的过程中,我得到了如下所示的异常 ██╗ ██╗ ██╗ ████████╗ ███████╗ ██████╗ ████████╗ ████████╗ ███████╗ ██║ ██║ ██║ ╚══██╔══╝ ██╔═══██╗ ██

在JHipster注册表中集中micro service客户端配置的过程中,我目前面临一个问题。我正在使用文件系统方法来集中注册表应用程序的配置(中央配置)文件夹

在运行时启动micro service客户端应用程序的过程中,我得到了如下所示的异常


        ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
        ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
        ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝
  ██╗   ██║ ██╔═══██║    ██║    ██╔════╝   ╚═══██╗    ██║    ██╔═══╝   ██╔══██║
  ╚██████╔╝ ██║   ██║ ████████╗ ██║       ██████╔╝    ██║    ████████╗ ██║  ╚██╗
   ╚═════╝  ╚═╝   ╚═╝ ╚═══════╝ ╚═╝       ╚═════╝     ╚═╝    ╚═══════╝ ╚═╝   ╚═╝

:: JHipster ?  :: Running Spring Boot 2.1.6.RELEASE ::
:: https://www.jhipster.tech ::

2020-09-14 12:09:12.061  INFO 3828 --- [  restartedMain] c.t.g.GlueResourceDataServiceApp         : The following profiles are active: dev
2020-09-14 12:09:16.314  WARN 3828 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'processorStorageGateway' defined in null: Cannot register bean definition [Generic bean: class [org.springframework.integration.gateway.GatewayProxyFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'processorStorageGateway': There is already [Generic bean: class [org.springframework.integration.gateway.GatewayProxyFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
2020-09-14 12:09:16.342 ERROR 3828 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'processorStorageGateway', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

我尝试过使用注册表应用程序的中央配置文件夹.yml文件中的属性(该文件保存客户端应用程序的中央配置)这样的方法

但是还没有运气。 我还尝试在bean注入失败的接口上定义@Service annotation,如下所示

@MessagingGateway
@Service
public interface ProcessorStorageGateway { 
..... }

我看到了两个引用类文件,它们使用这个接口自动连接 FailJobscheduler和ExternalQueuelistener试图在运行时注入此bean“processorGateway”类型的接口,重命名其autowiring属性也无助于解决此问题,如下所述

@Component
public class FailJobsScheduler {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private JobService jobService;

    @Autowired
    private ProcessorStorageGateway processorStorageGateway;
............
}

@Service
public class ExternalQueueListener {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ProcessorStorageGateway processorStorageGateway;
.....
}

目前,由于Spring Boot-2.1以后的版本在运行时不允许默认bean重写,所以无法解决这个问题。
开始时提到的上述打击和审判也无济于事。有人能就这个问题提供建议吗?最好的解决方法是什么?

上述问题已经通过避免一些重复的Spring注释得到了解决,这些注释已经出现在project中,在诸如@Configuration等的进一步调查中,以及在主Spring BOOT应用程序类中,通过提及要对各个包执行的组件扫描,帮助解决了问题

@Component
public class FailJobsScheduler {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private JobService jobService;

    @Autowired
    private ProcessorStorageGateway processorStorageGateway;
............
}

@Service
public class ExternalQueueListener {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ProcessorStorageGateway processorStorageGateway;
.....
}