返回顶部

eureka相关异常

1. eureka相关异常

1.1. 异常信息

Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not a

1.2. 解决

  1. 上述异常我在两处地方遇到过,一是在集成txLCN分布式服务时,用到eureka注册的时候,需要额外添加两个配置类
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;
    }
}

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;
    }
}

否则也会报上述错误
2. 二是再junit的Test类中,用@SpringBootTest创建测试的时候,若是报上述错误,可通过在任意spring能扫到的位置添加一个类即可

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

posted @ 2019-02-12 17:44  老梁讲Java  阅读(1728)  评论(0)    收藏  举报
编辑推荐:
· 还在手写JSON调教大模型?.NET 9有新玩法
· 复杂业务系统线上问题排查过程
· 通过抓包,深入揭秘MCP协议底层通信
· 记一次.NET MAUI项目中绑定Android库实现硬件控制的开发经历
· 糊涂啊!这个需求居然没想到用时间轮来解决
阅读排行:
· Coze Studio:字节跳动 Coze 的开源版本来了!第一时间深度解析
· 为大模型 MCP Code Interpreter 而生:C# Runner 开源发布
· 复杂业务系统线上问题排查过程
· 独立开发:高效集成大模型,看这篇就够了
· 在SqlSugar的开发框架的Vue3+ElementPlus前端中增加对报表模块的封装处理,实现常
点击右上角即可分享
微信分享提示