2019-05-27 | UNLOCK

(Spring Cloud微服务实战-书中之坑)分布式服务跟踪:Spring Cloud Sleuth 快速入门

按照书中的快速入门案例,在pom.xml文件中加入eureka和ribbon依赖

<artifactId>spring-cloud-starter-eureka</artifactId>
<artifactId>spring-cloud-starter-ribbon</artifactId>

分别实现trace-1和trace-2接口,发送POST请求出错:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed May 15 20:39:45 CST 2019
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported

解决办法: 依赖改为:
spring-cloud-starter-netflix-eureka-server
spring-cloud-starter-netflix-ribbon

只需要把trace1的RequestMethod.GET改为POST即可,trace2不需要改
@RequestMapping(value = "/trace-1", method = RequestMethod.POST)
public String trace(){
System.out.println("===call trace-1===");
return restTemplate().getForEntity("http://TRACE-2/trace-2", String.class).getBody(); }

@RequestMapping(value = "/trace-2", method = RequestMethod.GET)
public String trace(){
System.out.println("======");
return "Trace";
}
版本问题是个令人头疼的问题,书中也有各种坑ヽ(ー_ー)ノ

评论加载中