我正在使用 Eureka 服务注册表设置 Spring Boot 微服务基础架构。
我正在使用 RestTemplate 在本地调用另一个服务(通过 Eureka 完成解析),它运行完美!但是在 Cloud Foundry 上调用服务时,我总是收到“301 Moved Permanent”错误代码。
任何人都知道 RestTemplate 是否需要特定配置才能在 Cloud Foundry 上与 Eureka 一起使用?
@Bean
@LoadBalanced
RestTemplate getRestTemplate() {
return new RestTemplate();
}
public UserMapping getUserMappingFromRemoteServer(String name_id){
UserMapping userMappingResponse = mappingTemplate.getForObject("http://user-mapping/user?id=" + name_id, UserMapping.class);
}
我的回应总是
Setting request Accept header to [application/json, application/*+json]
Created GET request for "http://user-mapping/user?id=1"
GET request for "http://user-mapping/user?id=1" resulted in 301 (MOVED_PERMANENTLY)
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.user.SmartCharging.UserMapping] and content type [text/html]]