我遇到了编译时错误
call(play.mvc.Http.Context) in actions.Headers cannot override call(play.mvc.Http.Context) in play.mvc.Action
[error] overridden method does not throw java.lang.Exception
[error] public CompletionStage<Result> call(final Http.Context ctx) throws Throwable {
这是代码:
public CompletionStage<Result> call(final Http.Context ctx) throws Throwable {
ctx.response().setHeader("Access-Control-Allow-Origin", "*");
ctx.response().setHeader("Allow", "*");
ctx.response().setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
ctx.response().setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Referer, User-Agent, token");
ctx.response().setHeader("Access-Control-Expose-Headers", "Origin, X-Requested-With, Content-Type, Accept, Referer, User-Agent, token");
return (CompletionStage<Result>) delegate.call(ctx);
}
我正在使用剧本framework 2.6
答案 0 :(得分:2)
根据playframework 2.6的documentation,类Action中的方法调用不再抛出Thowable,因此您的方法也不必这样做。
答案 1 :(得分:1)
只需从方法声明中删除[throws Throwable]。