首页 技术 正文
技术 2022年11月23日
0 收藏 302 点赞 3,998 浏览 2351 个字

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

微信扫一扫

支付宝扫一扫

本文网址:https://www.zhankr.net/141272.html

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:7,097
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:4,454
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:566 阅读:5,265
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:5,147
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:6,314
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:3,859