无法使用返回 play.mvc.WebSocket 的方法作为 Play 请求的处理程序?
Cannot use a method returning play.mvc.WebSocket as a Handler for requests in Play?
GET /status controllers.Application.handleWebSocketConnection()
这里是相关的源代码。
public WebSocket handleWebSocketConnection() {
return WebSocket.withActor(new F.Function<ActorRef, Props>() {
@Override
public Props apply(ActorRef actorRef) throws Throwable {
return UserActor.props(actorRef, "");
}
});
}
这是我的 build.sbt
import play.routes.compiler.InjectedRoutesGenerator
import play.sbt.PlayScala
name := "hello"
version := "1.0"
lazy val `dashboard` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
jdbc ,
cache ,
ws ,
specs2 % Test,
"io.netty" % "netty-all" % "4.0.0"
)
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
resolvers ++= Seq(
"scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
)
routesGenerator := InjectedRoutesGenerator
fork in run := true
我正在使用 Play 版本 2.4.2,所有源代码都在 java 8. 我收到以下错误。我不确定我的路线和控制器发生了什么。我在这里关注了 link。
[error] /Users/hello/Documents/java/test_app/conf/routes:8: Cannot use a method returning play.mvc.WebSocket[?0] as a Handler for requests
[error] GET /status controllers.Application.handleWebSocketConnection()
[error] /Users/hello/Documents/java/test_app/conf/routes:8: not enough arguments for method createInvoker: (implicit hif: play.core.routing.HandlerInvokerFactory[play.mvc.WebSocket[?0]])play.core.routing.HandlerInvoker[play.mvc.WebSocket[?0]].
[error] two errors found
[error] (compile:compile) Compilation failed
有什么想法吗?
我没有添加评论所需的代表...所以我们开始吧:
我想知道指定由您的 websocket 处理的消息类型是否可以解决问题,请尝试:
public WebSocket<String> handleWebSocketConnection()
这当然是假设您的 websocket 期待来自浏览器的字符串以及发送回的字符串。
GET /status controllers.Application.handleWebSocketConnection()
这里是相关的源代码。
public WebSocket handleWebSocketConnection() {
return WebSocket.withActor(new F.Function<ActorRef, Props>() {
@Override
public Props apply(ActorRef actorRef) throws Throwable {
return UserActor.props(actorRef, "");
}
});
}
这是我的 build.sbt
import play.routes.compiler.InjectedRoutesGenerator
import play.sbt.PlayScala
name := "hello"
version := "1.0"
lazy val `dashboard` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
jdbc ,
cache ,
ws ,
specs2 % Test,
"io.netty" % "netty-all" % "4.0.0"
)
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
resolvers ++= Seq(
"scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
)
routesGenerator := InjectedRoutesGenerator
fork in run := true
我正在使用 Play 版本 2.4.2,所有源代码都在 java 8. 我收到以下错误。我不确定我的路线和控制器发生了什么。我在这里关注了 link。
[error] /Users/hello/Documents/java/test_app/conf/routes:8: Cannot use a method returning play.mvc.WebSocket[?0] as a Handler for requests
[error] GET /status controllers.Application.handleWebSocketConnection()
[error] /Users/hello/Documents/java/test_app/conf/routes:8: not enough arguments for method createInvoker: (implicit hif: play.core.routing.HandlerInvokerFactory[play.mvc.WebSocket[?0]])play.core.routing.HandlerInvoker[play.mvc.WebSocket[?0]].
[error] two errors found
[error] (compile:compile) Compilation failed
有什么想法吗?
我没有添加评论所需的代表...所以我们开始吧:
我想知道指定由您的 websocket 处理的消息类型是否可以解决问题,请尝试:
public WebSocket<String> handleWebSocketConnection()
这当然是假设您的 websocket 期待来自浏览器的字符串以及发送回的字符串。