问题描述
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
here is my 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中.出现以下错误.我不确定我的路线和控制器在做什么.我在这里点击了链接.
I am using Play version 2.4.2 and all the source code is in java 8. I get the following error. I am not sure what is going with my routes and the controller. I followed the link here.
[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
有什么想法吗?
推荐答案
我没有需要添加评论的代表...所以我们开始:
I don't have the rep needed to add a comment... so here we go:
我想知道指定您的websocket处理的消息类型是否可以解决此问题,请尝试:
I'm wondering if specifying the type of messages handled by your websocket would fix the problem, try:
public WebSocket<String> handleWebSocketConnection()
这当然是假设您的websocket期望从浏览器输入字符串以及将字符串发送回.
This is of course assuming your websocket is expecting Strings coming in from the browser as welle as send Strings back.
这篇关于无法使用将play.mvc.WebSocket返回为Play中请求的处理程序的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!