使用JHipster-Registry云配置服务器作为中央服务器集中化微服务时,Bean定义覆盖异常

问题描述

jhipster-registry中集中微服务客户端的配置期间,我目前面临一个问题。我正在使用文件系统方法来集中注册表应用程序的配置(central-config文件夹。

在运行时启动微服务客户端应用程序时,出现如下所示的异常


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

:: 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

我尝试过使用注册表应用程序的Central-config文件夹.yml文件(其中包含客户端应用程序的中央配置)中的属性方法

spring:
    
    main:
        allow-bean-deFinition-overriding: true

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

@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注释得以解决,这些注释已在项目中进行了进一步的研究(例如@Configuration等),并且在主Spring-BOOT应用程序类中通过提及要为组件执行的组件扫描而避免了各自的软件包可帮助解决问题