先记录现象:

dubbo整合zipkin时,我的配置文件是这样的

@Bean("okHttpSender")
public OkHttpSenderFactoryBean okHttpSender(){
OkHttpSenderFactoryBean okHttpSenderFactoryBean = new OkHttpSenderFactoryBean();
//zipkin服务端
okHttpSenderFactoryBean.setEndpoint("http://localhost:9411/api/v2/spans");
return okHttpSenderFactoryBean;
} @Bean
public AsyncReporterFactoryBean reporter(@Qualifier("okHttpSender")OkHttpSender sender){
AsyncReporterFactoryBean asyncReporterFactoryBean = new AsyncReporterFactoryBean();
asyncReporterFactoryBean.setSender(sender);
asyncReporterFactoryBean.setCloseTimeout(1000);
return asyncReporterFactoryBean;
} @Bean("tracing")
public TracingFactoryBean tracingFactoryBean(@Qualifier("reporter") Reporter reporter) throws Exception {
TracingFactoryBean tracingFactoryBean = new TracingFactoryBean();
tracingFactoryBean.setLocalServiceName("rcinvestTracing");
tracingFactoryBean.setSpanReporter(reporter);
CurrentTraceContextFactoryBean currentTraceContextFactoryBean = new CurrentTraceContextFactoryBean();
CurrentTraceContext.ScopeDecorator scopeDecorator = MDCScopeDecorator.create();
currentTraceContextFactoryBean.setScopeDecorators(Arrays.asList(scopeDecorator));
tracingFactoryBean.setCurrentTraceContext(currentTraceContextFactoryBean.getObject());
return tracingFactoryBean;
}

结果提示自动注入没有发现reporter

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'zipkin2.reporter.Reporter<?>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=reporter)}

然后我改了一下

 public TracingFactoryBean tracingFactoryBean(@Qualifier("reporter") Reporter reporter) throws Exception
改为:
public TracingFactoryBean tracingFactoryBean(@Qualifier("reporter") AsyncReporterFactoryBean reporter) throws Exception

又提示循环注入:

Requested bean is currently in creation: Is there an unresolvable circular reference?

虽然通过源码发现了导致问题的源码,但是我也不知道具体是什么原因导致的问题

最后通过修改bean加载的顺序,上述俩个问题都解决了

@Bean("tracing")
public TracingFactoryBean tracingFactoryBean(@Qualifier("reporter") AsyncReporter reporter) throws Exception {
TracingFactoryBean tracingFactoryBean = new TracingFactoryBean();
tracingFactoryBean.setLocalServiceName("rcinvestTracing");
tracingFactoryBean.setSpanReporter(reporter);
CurrentTraceContextFactoryBean currentTraceContextFactoryBean = new CurrentTraceContextFactoryBean();
CurrentTraceContext.ScopeDecorator scopeDecorator = MDCScopeDecorator.create();
currentTraceContextFactoryBean.setScopeDecorators(Arrays.asList(scopeDecorator));
tracingFactoryBean.setCurrentTraceContext(currentTraceContextFactoryBean.getObject());
return tracingFactoryBean;
} @Bean
public AsyncReporterFactoryBean reporter(@Qualifier("okHttpSender")OkHttpSender sender){
AsyncReporterFactoryBean asyncReporterFactoryBean = new AsyncReporterFactoryBean();
asyncReporterFactoryBean.setSender(sender);
asyncReporterFactoryBean.setCloseTimeout(1000);
return asyncReporterFactoryBean;
} @Bean("okHttpSender")
public OkHttpSenderFactoryBean okHttpSender(){
OkHttpSenderFactoryBean okHttpSenderFactoryBean = new OkHttpSenderFactoryBean();
//zipkin服务端
okHttpSenderFactoryBean.setEndpoint("http://localhost:9411/api/v2/spans");
return okHttpSenderFactoryBean;
}

猜测:父级bean放在上面加载,需要注入的bean,放在下面加载是不是就能就觉问题

springboot由于bean加载顺序导致的问题的更多相关文章

  1. SpringBoot系列教程之Bean加载顺序之错误使用姿势辟谣

    在网上查询 Bean 的加载顺序时,看到了大量的文章中使用@Order注解的方式来控制 bean 的加载顺序,不知道写这些的博文的同学自己有没有实际的验证过,本文希望通过指出这些错误的使用姿势,让观文 ...

  2. SpringBoot中的bean加载顺序

    https://www.dazhuanlan.com/2019/10/22/5daebc5d16429/ 最近在做传统Spring项目到SpringBoot项目迁移过程中,遇到了一些bean加载顺序的 ...

  3. springboot 配置文件的加载顺序

    springboot 配置文件的加载顺序1.在命令行中传入的参数.2. SPRING APPLICATION JSON中的属性. SPRING_APPLICATION—JSON是以JSON格式配置在系 ...

  4. 【spring】bean加载顺序

    问题来源 有一个bean为A,一个bean为B.想要A在容器实例化的时候的一个属性name赋值为B的一个方法funB的返回值. 如果只是在A里单纯的写着: private B b; private S ...

  5. SpringBoot的配置文件加载顺序和使用方式

    1.bootstrap.properties bootstrap.properties 配置文件是由"根"上下文优先加载,程序启动之初就感知 如:Spring Cloud Conf ...

  6. spring bean加载顺序指定方式之一

    在某些情况下,我们在容器启动的时候做一些事情,举个例子,加载缓存等.. 此时我们会希望某个bean先被加载并执行其中的afterpropertiesset方法. 因为spring默认是通过contex ...

  7. 记录一个bootstrap因js加载顺序导致的问题(tstrap-table-mobile.min.js:7 Uncaught TypeError: Cannot read property 'defaults' of undefined)

    问题描述: 网上找了会没看到答案,然后看了下源码,发现也没有问题,想到js加载的顺序,改了下,发现问题没了. 正确的顺序: 我之前把 <script src="/js/plugins/ ...

  8. iframe加载顺序导致数据访问出现问题

    背景: 一个页面A内有一个iframe,src指向了B页面. 问题: 页面A通过Ajax获取服务器数据,并赋值给了页面A的全局变量gData,页面B要用到页面A的数据gData.那么问题来了当B访问g ...

  9. SpringBoot的配置文件加载顺序以及如何获取jar包里的资源路径

    一.读取配置文件的四种方式 这四种配置文件放置方式的读取优先级依次递减,具体可以查看官方文档. 1.1jar包同级目录下的config文件夹里的配置文件 其实我以前就见过这种方式了,只是不知道怎么做的 ...

随机推荐

  1. js面向对象入门

    通常我们写js以及调用: function init(){ console.log("init") } function load(){ console.log("loa ...

  2. treeview判断节点是不是已存在

    /// <summary>        /// 判断treeView的节点是否已存在  treeView1.Nodes[0].Nodes        /// </summary& ...

  3. DML:增、删、改表中数据

    1. 添加数据 (1) 常规添加 INSERT INTO 表名(列名,列名,列名) VALUES(值,值,值); (2) 简化添加 INSERT INTO 表名 VALUES(值,值,值); 规则: ...

  4. TPCH测试工具

    TPC现有的测试标准为:TPC-E.TPC-C.TPC-H.TPC-App.根据这4个测试基准,目前TPC主要包括的4个技术小组委员会:TPC-E 技术小组委员会.TPC-C 技术小组委员会.TPC- ...

  5. 如何在国内使用google

    而Google却一直坚持“机器算法”至上,让信息以公正的排序结果呈现,对于IT人员来说国内不能用google进行搜索是很痛苦的. 公司邮件介绍了一些方法,mark一下还是很有用的. http://ww ...

  6. 关于Jetson Kit开发相关资料

    首先是nVidia官方对于Jetson Kit的介绍: http://www.nvidia.com/object/jetson-tk1-embedded-dev-kit.html https://de ...

  7. mongodb MongoDB C#/.NET driver version

    The first column lists the driver version(s). C#/.NET Driver Version MongoDB 2.6 MongoDB 3.0 MongoDB ...

  8. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_15-页面静态化-模板管理-模板管理业务流程

    在视频教学的过程中,不会去做模板管理的模块 cms_template用来存储模板信息 cms_page 这一些课程页面用的是一个模板 模板的详情.templateFileId是模板的文件id 模板的文 ...

  9. 阶段5 3.微服务项目【学成在线】_day02 CMS前端开发_11-webpack研究-npm和cnpm安装配置

    node.js安装完成后,就自动安装了webpack. npm -v:查看npm安装的版本 当前安装目录默认的包 在node.js的目录下创建两个文件夹 这样路径就被修改成功了 cnpm npm in ...

  10. 【转】【很全很新】C3P0 连接池和 DBUtils 配合事务使用总结

    [转]https://blog.csdn.net/guozhaohui628/article/details/84793028 很久没用原生连接池,最近想写个小功能,结果发现很多地方不太懂,然后网上搜 ...