我試圖實現非阻塞式調用。在春季4,但不幸的是它拋出了以下錯誤。類型不匹配:無法從字符串轉換爲ListenableFuture <String>
類型不匹配:不能從字符串轉換成ListenableFuture
,也同樣的錯誤不能轉換能夠從地圖ListenableFuture>。
我的方法調用堆棧如下。
ListenableFuture<Map<String,String>> unusedQuota = doLogin(userIdentity,request,"0");
doLogin登錄簡單地返回地圖
是有需要的任何轉換器?
需要做什麼修改?
感謝。
public class MyController {
final DeferredResult<Map<String,String>> deferredResult = new DeferredResult<Map<String,String>>(5000l);
private final Logger log = LoggerFactory.getLogger(MyController.class);
@Inject
RestTemplate restTemplate;
@RequestMapping(value = "/loginservice", method = RequestMethod.GET)
@Timed
public DeferredResult<Map<String,String>> loginRequestService(@RequestParam String userIdentity,HttpServletRequest request) throws Exception {
deferredResult.onTimeout(new Runnable() {
@Override
public void run() { // Retry on timeout
deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.REQUEST_TIMEOUT).body("Request timeout occurred."));
}
});
@SuppressWarnings("unchecked")
ListenableFuture<Map<String,String>> unusedQuota = doLogin(userIdentity,request);
unusedQuota.addCallback(new ListenableFutureCallback<Map<String,String>>() {
@SuppressWarnings("unchecked")
@Override
public void onSuccess(Map<String, String> result) {
// TODO Auto-generated method stub
deferredResult.setResult((Map<String, String>) ResponseEntity.ok(result));
}
@Override
public void onFailure(Throwable t) {
// TODO Auto-generated method stub
deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(t));
}
});
return deferredResult;
}
private Map<String,String> doLogin(String userIdentity,HttpServletRequest request) throws Exception{
Map<String,String> unusedQuota=new HashMap<String,String>();
unusedQuota.put("quota", "100");
return unusedQuota;
}
}
}
這是在控制器內嗎?發佈我們的整個方法代碼 – developer