启动服务的时候报了这个错误

org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:208) [spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1087) [spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.event.ApplicationListenerMethodAdapter.getTargetBean(ApplicationListenerMethodAdapter.java:288) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:258) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:180) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:142) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400) [spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:406) [spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354) [spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:998) [spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:965) [spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.cloud.context.named.NamedContextFactory.destroy(NamedContextFactory.java:76) [spring-cloud-context-2.0.2.RELEASE.jar:2.0.2.RELEASE]at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:256) [spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:571) [spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:543) [spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:954) [spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:504) [spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:961) [spring-beans-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1039) [spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1015) [spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:965) [spring-context-5.0.11.RELEASE.jar:5.0.11.RELEASE]at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:813) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230) [spring-boot-2.0.7.RELEASE.jar:2.0.7.RELEASE]at com.gwh.microserviceconsumermoviefeign.MicroserviceConsumerMovieFeignApplication.main(MicroserviceConsumerMovieFeignApplication.java:14) [classes/:na]

并不是微服务启动的时候报错,是微服务已经起来了,运行了一段时间就挂了,日志见上。大致意思应该是我的服务没办法注册到Eureka中心。

解决办法:

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;import java.util.Arrays;@Component
public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor {@Overridepublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) {BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");bd.setDependsOn("eurekaAutoServiceRegistration");}}private boolean containsBeanDefinition(ConfigurableListableBeanFactory beanFactory, String... beans) {return Arrays.stream(beans).allMatch(b -> beanFactory.containsBeanDefinition(b));}
}

但是我发现这个解决办法有1个漏洞就是,当我第一次启动的时候报了端口被占用,我这个服务的端口设置的8099,但是他提示的却是8080服务提供者的端口,我就尝试把服务提供者给停了,然后更换了端口再起来,然后启动消费者,这次竟然启动成功了

然后我把上面的配置类代码给注释了,然后clean,install一下,然后把端口改成8080再启动竟然也能启动成功。。。。

服务无法注册到注册中心解决相关推荐

  1. 注册中心解决了什么问题

    我们讲解了什么是服务注册中心,以及服务注册中心的作用,还有常见的服务注册中心有哪些,那我们继续往下讲解,我们主要讲解服务注册中心,它主要是帮我们解决什么样的问题,注册中心或者叫服务注册中心,解决了什么 ...

  2. SpringCloud微服务(四)——Nacos服务注册和配置中心

    SpringCloud Alibaba Nacos服务注册和配置中心 Spring Cloud Netflix Projects Entering Mainterance Mode SpringClo ...

  3. 服务注册与发现用mysql_yeasul: 轻量级服务注册与发现中心,具有健康检查功能。...

    yeasul 亿联定制版服务注册与发现中心,具备心跳检测功能,由于接口参考了consul,所以取名为yeasul. 项目架构 使用Java语言开发,依赖于MySQL 8.0数据库,基于Spring B ...

  4. 微服务系列之ZooKeeper注册中心和Nacos注册中心Nacos和Zookeeper对比

    一.ZooKeeper注册中心 Zookeeper 是 Apache Hadoop 的子项目,是一个树型的目录服务,支持变更推送,适合作为 Dubbo 服务的注册中心,工业强度较高,可用于生产环境,推 ...

  5. 微服务 注册中心的作用_微服务架构Dubbo之注册中心(Zookeeper)

    注册中心简介 在微服务架构中,注册中心是核心的基础服务之一.在微服务架构流行之前,注册中心就已经开始出现在分布式架构的系统中.Dubbo是一个在国内比较流行的分布式框架,被大量的中小型互联网公司所采用 ...

  6. 微信企业号已停止提供企业消息会话服务器,企业微信注册时显示会话服务已经被安装了怎么解决 解决攻略教程大全...

    2016年4月18日,腾讯正式发布全平台企业办公工具"企业微信",并通过腾讯应用宝独家首发安卓版."企业微信"的推出将为企业员工提供最基础和最实用的办公服务,并 ...

  7. Spring Cloud Alibaba配置实例nacos+sentinel+dubbo实行服务注册、配置中心、熔断限流

    通过Spring Cloud Alibaba相关组件nacos+sentinel+dubbo实行服务注册.配置中心.熔断限流等功能 1.本机安装nacos和sentinel-dashboard服务端 ...

  8. python consul配置中心_微服务注册发现配置中心-consul

    Consul详解 近期在微服务业务中用的注册中心,在此简单记录下以备后用. 一 概述 1.1 概念 Consul 是 HashiCorp 公司推出的开源工具,用于实现分布式系统的服务发现与配置.Con ...

  9. SpringCloud学习之(十八)SpringCloud Alibaba Nacos服务注册和配置中心

    文章目录 (十八)SpringCloud Alibaba Nacos服务注册和配置中心 1.Nacos简介 1.1 为什么叫Nacos 1.2 Nacos是什么 1.3 Nacos能干嘛 1.4 Na ...

最新文章

  1. 2022-2028年中国加密货币交易所市场研究及前瞻分析报告
  2. c语言合法常量2.57e03,[单选] 目前杭州共有世界遗产()项。
  3. 趣学python3(38)--多项式最小二乘法拟合
  4. PowerPC汇编指令
  5. angular js 使用pdf.js_胶水(框架) Stencil.js
  6. POJ3278 HDU2717 Catch That Cow【BFS】
  7. java 广播模式_Java设计模式——观察者模式的灵活应用
  8. 55. Yii import class 与 对象创建
  9. es的query及filter 1
  10. 2021朝阳启声学校高考成绩查询,梦在前方 路在脚下 ———潮阳启声学校2019届高考80天誓师大会...
  11. 洛谷P3533 [POI2012]RAN-Rendezvous
  12. 【vendor】Go 包依赖管理工具govendor
  13. 多因子风险建模-协方差矩阵、投资组合风险
  14. c++我的世界小游戏
  15. ChatGPT桌面应用【保姆级教程、亲测可用】mac、windows双系统推荐
  16. 创建带头结点单链表实现二进制数加1的运算
  17. 专访海尔小帅影院创始人马文俊:硬件不是未来 需求才是未来
  18. 持续部署编排的另类选择:使用Node-RED进行容器化部署
  19. java调用扫描仪_通过Java调用Dynamsoft .NET TWAIN SDK控制扫描仪扫描文档
  20. 面向对象设计模式之备忘录模式

热门文章

  1. 微信小程序——【云音乐播放器】
  2. 大型医院影像PACS系统三维重建技术(获取数据、预处理、配准、重建和可视化)
  3. hdu4745(最长回文子序列)
  4. 如何做好项目沟通管理
  5. jieba 详细介绍
  6. 讲人话科普,Python是个啥?为啥大家都在学?
  7. mysql 查询关键字有中文_Laravel Backpack 后台列表页面查询关键词包含中文时报错...
  8. 文件操作之不得不知的细节
  9. Python爬虫入门实例四之百度、360搜索关键字提交(可自主输入关键字)
  10. unity接入讯飞AIUI(Windows SDK)