我正在使用播放框架2.4,然后由于某种原因我不得不将其升级到2.6版,然后我的代码开始出现编译时错误 这是我得到的错误
/myproject/app/controllers/UserGeneralController.java:44: cannot find symbol
[error] symbol: class Promise
[error] location: class controllers.UserGeneralController
[error] Promise<JsonObject> promise = PromiseHandler.getPromise(actorRef, request, 60000);
他们从link说到
将所有返回F.Promise的代码更改为返回CompletionStage。
所以我更改了代码 这是破旧的代码
Promise<JsonObject> promise = PromiseHandler.getPromise(actorRef, request, 60000);
JsonObject response = null;
Result result = null;
try {
response = promise.get(60000);
log.debug("saveUserAccountInfo: >> response object >> {}", response);
result = PlayResultHandler.getResult(response.get("status").getAsInt(),
JsonHandler.parseJsonIntoString(response));
} catch (Exception e) {
}
这是我在play 2.6的代码中所做的更改
import java.util.concurrent.CompletionStage;
CompletionStage<JsonObject> promise = PromiseHandler.getPromise(actorRef, request, 6000);
Result result = null;
try {
response = ((JsonObject) promise.get(60000));
log.debug(">> response object >> {}", response);
result = PlayResultHandler.getResult(response.get("status").getAsInt(), JsonHandler.parseJsonIntoString(response));
} catch (Exception e) {
}
此后,我在
上出错response = promise.get(60000);
/myproject/app/controllers/UserGenralController.java:42: cannot find symbol
[error] symbol: method get(int)
[error] location: variable promise of type java.util.concurrent.CompletionStage<com.google.gson.JsonObject>
[error] response = promise.get(60000);
在获得帮助之前,如何从中获取json对象