我们正在将项目从Play Framework 2.1升级到2.2。但是,新的结果结构不起作用。我在此Global.java文件的'call'函数中将返回类型 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)
不兼容
感谢。