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文件發生變化,導致部署信息發生變化。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM