记Spring Cloud 学习中遇见的问题
博主在今年早些时候曾部分学习过Spring Cloud,后因工作搁置,2018/10/17决定重新复习一遍,这篇文章用来记述在学习过程中遇见的零散的小问题。
附上教程地址:https://blog.csdn.net/forezp/article/details/81040925
2018/10/17
cannot find declaration to go to:java文件不编译,不报错。如下:
解决方案:
注:之后可能需要重新编译,或者重新打开项目
2018/10/18
学习Feign的时候发现链接不能访问:
后台没有报错,也没有访问日志,可能是Controller没有扫描到,按照网友的说法,在@SpringBootApplication下添加@ComponentScan(basePackages = {""}) ,但这使我产生了疑惑为什么偏偏只有这个模块需要添加,然后仔细检查了一下:
都是细节惹的祸。。。
正确的应该是这样:
2018/10/19
1、
在使用断路器Hystrix的时候,注解@HystrixCommand不能解析,原因是此注解在新版本中移除了,需重新在pom.xml添加依赖:
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
<version>RELEASE</version>
</dependency>
2、
Ribbon配置仪表盘加载不出来,报错:Unable to connect to Command Metric Stream.
网上很多解决方案都是配置:
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
但看到一篇文章另辟蹊径,
https://my.oschina.net/u/3651261/blog/1841980
用以下方法解决:
添加配置
management.endpoints.web.exposure.include=hystrix.stream
访问的时候使用地址:
http://localhost:port/actuator/hystrix.stream
结果成功访问
注:Feign的时候,要添加注解 @EnableCircuitBreaker
因为Ribbon使用@EnableHystrix注解,这个注解已经包含了@EnableCircuitBreaker注解。
而Feign使用@EnableFeignClinets注解,该注解不包含@EnableCircuitBreaker注解。所以要专门加上。
2018/10/22
整合zuul的时候断路器不起作用,显示Whitelabel Error Page,并且后台报错:
com.netflix.zuul.exception.ZuulException: Forwarding error
网上的说法是要设置超时时间,在配置文件中添加配置:
zuul:
host:
connect-timeout-millis: 1000
socket-timeout-millis: 3000
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 3000
ribbon:
ReadTimeout: 3000
ConnectTimeout: 3000
但很遗憾对并不起作用,后来发现要这样配置,feign与ribbon一样:
hystrix:
command:
default:
execution:
timeout:
enabled: false
ribbon:
ReadTimeout: 3000
ConnectTimeout: 3000
2018/10/23
Spring Cloud Config注意点:
在config-client中开启从配置中心读取文件
spring.cloud.config.discovery.enabled=true
配置信息(包括端口等)将不再使用本地的,而使用config-server中配置的文件指向的地址
spring.cloud.config.server.git.uri=https://github.com/lcz92416/springcloudtest/
spring.cloud.config.server.git.searchPaths=config-server/src/main/resources
2018/10/24
1、安装完Rabbit,发现管理页面不能访问
http://localhost:15672
解决方案:
执行命令
rabbitmq-plugins enable rabbitmq_management
2、bus刷新配置不管用
http://localhost:8765/actuator/bus-refresh
配置文件要如下配置:
@RefreshScope注解,要加在这个地方