我已经配置了服务和客户端并部署到 PCF Cloud 中。我还将这两个应用程序绑定到服务注册表。由于我已使用 Service Registry 绑定服务,因此我正在尝试使用在 bootstrap.yml 文件中配置的名称访问客户端中的服务应用程序。我收到“没有可用于服务应用程序的实例”错误。
以下是我遵循的配置。服务:
@SpringBootApplication
@EnableDiscoveryClient
public class Application {}
应用程序属性:
spring.cloud.services.registrationMethod = route
security.basic.enabled=false
引导程序.yml:
spring:
application:
name: service-app
和一个小控制器
@RestController
@RequestMapping(value = "/calculate")
public class CalculationService {
@RequestMapping(value = "/addition", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public int addition(@QueryParam("X") int X, @QueryParam("Y") int Y) {
return X + Y;
}
}
客户:
@SpringBootApplication
@EnableDiscoveryClient
public class Application {}
应用程序属性:
spring.cloud.services.registrationMethod = route
security.basic.enabled=false
引导程序.yml
spring:
application:
name: compute-client
和一个控制器使用它的名字访问服务。
@Autowired
RestTemplate restTemplate;
@RequestMapping(value = "/addition/{X}/{Y}")
public int addition(@PathVariable int X, @PathVariable int Y) {
String uri = "https://service-app/calculate/addition?X=" + X + "&Y=" + Y;
return restTemplate.getForObject(uri, Integer.class);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
这两个应用程序都被推送到 PCF 并绑定到 Service Registry。我可以通过它的路线访问服务。当我尝试访问客户端时,它给了我错误
{
"timestamp": 1524236514920,
"status": 500,
"error": "Internal Server Error",
"exception": "java.lang.IllegalStateException",
"message": "No instances available for service-app",
"path": "/calculate/addition/14/13"
}
我错过了什么?