欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

eureka相关异常

程序员文章站 2023-12-25 11:56:39
1. eureka相关异常 1.1. 异常信息 1.2. 解决 1. 上述异常我在两处地方遇到过,一是在集成txLCN分布式服务时,用到eureka注册的时候,需要额外添加两个配置类 否则也会报上述错误 2. 二是再junit的Test类中,用@SpringBootTest创建测试的时候,若是报上述 ......

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

否则也会报上述错误

  1. 二是再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

上一篇:

下一篇: