zipkin:和springcloud集成过程记录

发现全是springcloudapp的名称,然后是springcloudapp(http://localhost:8080/hello/tom)工程单独调用并没有通知zipkin;
原来是因为restTemplate的获取,好用的是使用restTemplate的@autowire的方式,但是如果使用@autowired导致的异常:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appServer': Unsatisfied dependency expressed through field 'restTemplate': No qualifying bean of type [org.springframework.web.client.RestTemplate] found for dependency [org.springframework.web.client.RestTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.client.RestTemplate] found for dependency [org.springframework.web.client.RestTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.client.RestTemplate] found for dependency [org.springframework.web.client.RestTemplate]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
原因就是这个@Autowired声明必须要有bean定义,但是当前的工程极简,根本没有spring的配置文件来配置这个字段,但是可以采用“监守自盗”的方式,就是在一个类中声明既声明了bean,也声明了@autowired;为什么要做这么做?因为@autowired声明后,spring将会管理这个对象的生命周期,就可以在这个对象创建的前后放入钩子(拦截器)对其进行处理,比如zipkin就是通过spring拦截了restTemplate的创建,使其可以拦截restTemplate的invokeUrl方法,实现日志收集。
1 @Autowired
2 RestTemplate restTemplate;
3  
4 @Bean
5 public RestTemplate getRestTemplate() {
6   return new RestTemplate();
7 }
 
后来又碰到了一个问题,就是gateway异常;后来才发现因为appServer的eureka没有配置(调试上面问题的时候,从别的好用的程序拷贝过来application.properites,内容直接干掉了,好用的那段配置没有配eureka);后来添加上了问题解决;
 
但是我发现一旦这种情况发生,zuul竟然就崩溃了,再也无法提供服务?
(未解)
 
dubbo的web工程没有反应了?
因为没有配置Spring,需要在WEB-INF下面添加一些spring相关的位置xml;
 
为什么调不通spring-app?
没加@RestController,所以mapping没有创建,这一点从控制台日志可以看到,没有mapping /cloud/{name};
 
网关又挂了,http://localhost:8083/app/cloud/Jim 怎么跳转不过去了?
后来重新编译一下好了,还是那个问题,网关一旦爆了一次异常,之后就挂了。
 
怎么zipkin又不好用了?调用8083zipkin什么记录也没有?
发现app和dubbo服务都没有问题;那就是网关的zipkin配置问题了,突然想到只是添加了zuul的pom文件中间了zipkin和sleth的引用,好像没有添加配置文件啊!但是后来确认不是配置文件没有添加的事情,而是因为配置文件的写法问题,zipkin的配置路径之前是base-url,改为baseUrl,zipkin可以获取zuul的日志啦!看来properties文件和yaml文件命名规则不一样,两个单词在properties是使用“-”做分割,都是小写;但是yaml文件则是驼峰命名方式。
 
刚才怎么调试maven的web工程的web都无法跑到spring,maven引用一切都没问题。
狂晕!发现在Deployment Assembly里面竟然没有引用maven的lib,导致部署的WEB-INF/lib下面毛jar包都没有。超级晕倒。据说每次maven的update,都会导致project文件发生变化,导致部署信息发生变化。
原文地址:https://www.cnblogs.com/xiashiwendao/p/8834876.html