前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >eureka相关异常

eureka相关异常

作者头像
老梁
发布2019-09-10 18:15:55
3780
发布2019-09-10 18:15:55
举报
文章被收录于专栏:Java工程师成长之路

1. eureka相关异常

1.1. 异常信息

代码语言:javascript
复制
Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not a

1.2. 解决

  1. 上述异常我在两处地方遇到过,一是在集成txLCN分布式服务时,用到eureka注册的时候,需要额外添加两个配置类
代码语言:javascript
复制
package com.zhiyis.framework.service.tx;

import com.codingapi.tx.netty.service.TxManagerHttpRequestService;
import com.lorne.core.framework.utils.http.HttpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * create by lorne on 2017/11/18
 */

@Service
@Slf4j
public class TxManagerHttpRequestServiceImpl implements TxManagerHttpRequestService{

    @Override
    public String httpGet(String url) {
        log.info("httpGet-start");
        String res = HttpUtils.get(url);
        log.info("httpGet-end");
        return res;
    }

    @Override
    public String httpPost(String url, String params) {
        log.info("httpPost-start");
        String res = HttpUtils.post(url,params);
        log.info("httpPost-end");
        return res;
    }
}
代码语言:javascript
复制
package com.zhiyis.framework.service.tx;

import com.codingapi.tx.config.service.TxManagerTxUrlService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * create by lorne on 2017/11/18
 */
@Service
@Slf4j
public class TxManagerTxUrlServiceImpl implements TxManagerTxUrlService {


    @Value("${tm.manager.url}")
    private String url;

    @Override
    public String getTxUrl() {
        log.info("load tm.manager.url :{}", url);
        return url;
    }
}

否则也会报上述错误

  1. 二是再junit的Test类中,用@SpringBootTest创建测试的时候,若是报上述错误,可通过在任意spring能扫到的位置添加一个类即可
代码语言:javascript
复制
package com.zhiyis.framework.lock;

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 {

    @Override
    public 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));
    }
}

参考 https://blog.csdn.net/lililuni/article/details/83105045

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-02-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. eureka相关异常
    • 1.1. 异常信息
      • 1.2. 解决
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档