如何将A记录路由到Play Framework 2.2.x中的特定控制器操作?

时间:2014-02-24 14:51:40

标签: routes playframework-2.2

基本上,我希望将所有请求路由到特定的A记录(根域记录,例如http://example.com)到我的Playframework 2.2.1应用程序中的特定控制器操作(controllers.Application.other())

根据解释over here,我理解我需要覆盖Global对象中的onRouteRequest并在那里执行注入路由。

但是对于我的生活,我无法让James Roper的榜样奏效(我认为这是因为Playframework版本)。覆盖函数如下所示:

import ....

object Global extends WithFilters(requireSSL, new GzipFilter()) with GlobalSettings {

  override def onRouteRequest(request: RequestHeader): Option[Handler] = {
    (request.method, request.path) match {
      case ("GET", "example.com") => Some(controllers.Application.other)
      case _ => super.onRouteRequest(request)
    }
  }
}

    ....

产生:

type mismatch; found : play.mvc.Result required: play.api.mvc.Handler

我的controllers.Application.other动作非常基本,只渲染页面:

public static Result other() {
  return ok(views.html.indexOther());
}

我还尝试将 controllers.Application.other 更改为 controllers.routes.Application.other ,但之后它说它需要一个play.api.mvc.Handler而不是一个...呼叫,这是我猜的预期。

我发现this post更改了Playframework 2.2.1中请求标题的各个方面,我认为它可以帮助我解决我的问题,但我无法解决我想要重定向的控制器操作请求作为 play.api.mvc.Handler :(。

非常感谢任何帮助或解释!

1 个答案:

答案 0 :(得分:0)

回答我自己的问题:我们还没有找到解决方案。我们最终决定使用Scala控制器将Global onRouteRequest覆盖中的自定义路由指向。奇迹般有效。虽然混合Scala和Java控制器感觉有点痒。

相关问题