我在 AWS 上找不到合适的HttpMessageConverter发现错误,因为它在 Cloud Foundry 上工作正常,我得到了响应。
我是否需要为RestTemplate进行任何特殊配置才能在AWS上工作?
配置类
var Event = {
on: function(eventName, callback){
//todo
if(!this[eventName])
this[eventName] = [];
this[eventName].push(callback);
},
emit: function(eventName){
//todo
if(this[eventName])
Array.prototype.forEach.call(this[eventName], function(func){
func.call(this);
});
}
}
Event.on("one", function(){
console.log("go");
})
Event.on("one", function(){
console.log("gogo");
})
Event.emit("one");
var person1 = Object.assign({}, Event);
var person2 = Object.assign({}, Event);
person1.on("666", function(){
console.log("person1 666");
})
person2.on("777", function(){
console.log("person2 777");
})
person1.emit("666");
person1.emit("777");
person2.emit("777");
person2.emit("666");
客户端类
@Configuration
public class RestTemplateConfiguration {
@Bean
RestTemplate restTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setOutputStreaming(false);
RestTemplate restTemplate = new RestTemplate(requestFactory);
restTemplate.setErrorHandler(new RestResponseErrorHandler());
return restTemplate;
}
}
requestObj和ResponseObj类都是POJO类。
错误:
@Component
public class RestClient {
private final RestTemplate restTemplate;
@Autowired
public RestClient(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
public ResponseObj getData() {
return restTemplate.postForObject("http://somehost:port/data", requestObj, ResponseObj.class);
}
}