我已配置服务和客户端并部署到PCF Cloud中。我还将这两个应用程序绑定到Service Registry。由于我使用Service Registry绑定服务,因此我尝试使用在bootstrap.yml文件中配置的名称来访问客户端中的服务应用程序。我得到了#34;没有实例可用于service-app"错误。
以下是我遵循的配置。 服务:
@SpringBootApplication
@EnableDiscoveryClient
public class Application {}
application.properties:
spring.cloud.services.registrationMethod = route
security.basic.enabled=false
bootstrap.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 {}
application.properties:
spring.cloud.services.registrationMethod = route
security.basic.enabled=false
bootstrap.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"
}
我缺少什么?