簡體   English   中英

將Play框架從2.1更新到2.2:SimpleResult不起作用-編譯錯誤

[英]Play Framework update from 2.1 to 2.2: SimpleResult not working - compile error

我們正在將我們的項目從Play Framework 2.1升級到2.2。 但是,新的結果結構不起作用。 我已在此Global.java文件的“調用”函數中將返回類型Result更改為SimpleResult

public class Global extends GlobalSettings {

@Override
  public void onStart(Application app) {
    Logger.info("Global On Start event called");
    Logger.info("Admin Application has started");
    // get schedule duration from Application.conf
    Long scheduleDuration = Play.application().configuration().getLong("schedule-duration");
    Logger.debug("Scheduler duration is :"+ scheduleDuration) ;
    Logger.debug("Calling Schedule Service");
    Cancellable response1 = ScheduleService.scheduleIt(scheduleDuration);

    // get schedule duration for Worker Task Expiration Scheduler from application.conf
    Long workerTaskExpirationDuration = Play.application().configuration().getLong("worker-task-scheduler-interval");
    Cancellable response2 = TaskExpirationScheduleService.schedule(workerTaskExpirationDuration);
    /******************fix for CEA-3440*************************************/
    Long workerEmailDuration = Play.application().configuration().getLong("worker-email-scheduler-interval");
    Cancellable response3 = WorkerEmailScheduleService.schedule(workerEmailDuration);
     /******************fix for CEA-3440*************************************/
  }  

  @Override
  public void onStop(Application app) {
    Logger.info("Global On Stop event called");
    Logger.info("Application shutdown started..Stopping Sync Service Actor.");
    ActorRef syncActor = Akka.system().actorFor("/user/SyncServiceActor");
    Akka.system().stop(syncActor);
    Logger.info("Application shutdown started..Stopping Worker Task Expiration Actor.");
    ActorRef taskExpirationActor = Akka.system().actorFor("/user/WorkerTaskExpireActor");
    Akka.system().stop(taskExpirationActor);
     /******************fix for CEA-3440*************************************/
    Logger.info("Application shutdown started..Stopping Worker Email Actor.");
    ActorRef workerTaskExpirationDuration = Akka.system().actorFor("/user/WorkerTaskExpirationDuration");
    Akka.system().stop(workerTaskExpirationDuration);
     /******************fix for CEA-3440*************************************/
    // shut down system
    Akka.system().shutdown();
    Logger.info("Actor stopped and Akka System shutdown successfully..");
  }  




// For CORS
  private class ActionWrapper extends Action.Simple {
  public ActionWrapper(Action<?> action) {
  this.delegate = action;
  }

  @Override
  public Promise<SimpleResult> call(Http.Context ctx) throws java.lang.Throwable {
       Http.Response response = ctx.response();
       response.setHeader("Access-Control-Allow-Origin", "*");
       response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE"); 
       response.setHeader("Allow", "*"); 
       response.setHeader("Access-Control-Max-Age", "3600"); 
       response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Referer, User-Agent"); 
       response.setHeader("Access-Control-Allow-Credentials", "true"); 
       Promise<SimpleResult> result = (Promise<SimpleResult>) this.delegate.call(ctx);
       return result;
  }
  }

  @Override
  public Action<?> onRequest(Http.Request request, java.lang.reflect.Method actionMethod) {

  return new ActionWrapper(super.onRequest(request, actionMethod));
  }

}

在瀏覽器上進行編譯時,將產生以下錯誤:

編譯游戲項目

我試圖通過查看類似的StackOverflow問題來解決此問題,但無法解決問題。 我在Play方面相對較新,因此請詳細說明您的解決方案。

另外,我將Eclipse用作IDE,並收到以下錯誤:

返回類型與Action.call(Http.Context)不兼容

謝謝。

只需將Result替換為SimpleResult

這是一個動作的例子

public F.Promise<Result> call( Http.Context context ) throws Throwable {

    if ( !authorized ) {
        return F.Promise.promise(() -> unauthorized());
    }

    // execute the action
    return delegate.call( context );
}

這是我的Global.java

@Override
public F.Promise<Result> onError(Http.RequestHeader requestHeader, Throwable throwable) {
    if(Play.isDev()){
        return super.onError(requestHeader, throwable);
    }
    Logger.error("Error : ", throwable);
    return F.Promise.pure(Controller.ok(views.html.error.render(requestHeader.uri())));
}

您應該閱讀https://www.playframework.com/documentation/2.2.0/Migration22#New-results-structure-in-Java

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM