Cloudfoundry RestTemplate上的Eureka获得301永久移动

时间:2017-07-21 11:37:13

标签: spring-boot cloudfoundry resttemplate netflix-eureka netflix-ribbon

我正在使用Eureka Service Registry设置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]]

1 个答案:

答案 0 :(得分:0)

eureka:
  instance:
    non-secure-port-enabled: false
    secure-port-enabled: true

完成了这项工作