首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用JHipster-Registry集中微服务时出现Bean定义覆盖异常(云配置服务器作为中心服务器)

使用JHipster-Registry集中微服务时出现Bean定义覆盖异常(云配置服务器作为中心服务器)
EN

Stack Overflow用户
提问于 2020-09-14 15:01:24
回答 1查看 77关注 0票数 0

在JHipster-registry中集中微服务客户端的配置时,我目前遇到了一个问题。我正在使用文件系统的方法集中配置注册表应用程序的配置(central-config)文件夹。

在运行时启动微服务客户端应用时,我收到如下所示的异常

代码语言:javascript
复制
        ██╗ ██╗   ██╗ ████████╗ ███████╗   ██████╗ ████████╗ ████████╗ ███████╗
        ██║ ██║   ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
        ██║ ████████║    ██║    ███████╔╝ ╚█████╗     ██║    ██████╗   ███████╔╝
  ██╗   ██║ ██╔═══██║    ██║    ██╔════╝   ╚═══██╗    ██║    ██╔═══╝   ██╔══██║
  ╚██████╔╝ ██║   ██║ ████████╗ ██║       ██████╔╝    ██║    ████████╗ ██║  ╚██╗
   ╚═════╝  ╚═╝   ╚═╝ ╚═══════╝ ╚═╝       ╚═════╝     ╚═╝    ╚═══════╝ ╚═╝   ╚═╝

:: 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文件(保存客户端应用程序的中央配置)

代码语言:javascript
复制
spring:
    
    main:
        allow-bean-definition-overriding: true

但现在还不走运。我也尝试过在接口上定义@Service注解,根据上面的错误,它的bean注入失败,如下所示

代码语言:javascript
复制
@MessagingGateway
@Service
public interface ProcessorStorageGateway { 
..... }

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

代码语言:javascript
复制
@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覆盖在运行时是不允许的。开头提到的上述命中和试验也无济于事。有没有人能对这个面临的问题和解决它的最好方法提供建议?

EN

回答 1

Stack Overflow用户

发布于 2020-09-17 14:02:48

上述问题已通过避免一些重复的Spring注解得到解决,这些注解已经存在于项目中,在进一步的调查过程中,如@Configuration等,并且在主要Spring-BOOT应用程序类中,通过提及为各个包执行的组件扫描,帮助解决了该问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63879490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档