我正在使用Spring Cloud学习微服务。 这样的一个服务提供商:
@GetMapping(value = "/recommended")
public String readingList(){
return "Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)";
}
和一个这样的服务使用者:
public String readingList() {
URI uri = URI.create("http://localhost:8090/recommended");
return this.restTemplate.getForObject(uri, String.class);
}
@GetMapping("/to-read")
public String readingList() {
return bookService.readingList();
}
然后我使用邮递员发送请求“ http://localhost:8080/to-read”,并返回:
{
"timestamp": "2018-08-16T08:16:25.239+0000",
"status": 500,
"error": "Internal Server Error",
"message": "405 Method Not Allowed",
"path": "/to-read"
}
这是我porm.xml的一部分
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
更多代码:
@RestController
@EnableCircuitBreaker
@SpringBootApplication
....