希望有人可以提供帮助 . 我正在尝试从Play 2.4升级到2.5 . 升级后,我在JavaController类中遇到错误 . 其中一个错误表明
[error] /Play-2-JS-2.5/app/controllers/JavaController.java:87:java.util.concurrent.CompletionStage无法转换为play.libs.F.Promise [error] WS.url(“http ://示例.com“)获得()
看起来好像WSReponse可能在转到2.5时已被弃用 . 我试图用线路87 https://github.com/btgrant-76/Play-2-Java-Scala-Java-8-Async-Comparison/blob/6a85cf31cfb804ef20bacf8e14d30ce46cc9307c/app/controllers/JavaController.java#L87替换F.Promise和CompletionStage但是得到了同样的错误 . 我是've been googling for quite sometime and found topics around Dependency Injection however, there aren' t任何例子 . 任何例子和/或从这里去的地方都会很精彩 .
1 回答
如果你换了
同
仍然得到相同的错误,然后要检查的事项包括:
您是否在重新编译之前保存源代码?如果在错误消息中提到
F.Promise
但是没有't appear in the code, that' s可疑 . 在Play 2.5中,WSResponse.get
具有签名java.util.concurrent.CompletionStage<WSResponse> get()
所以F.Promise
不应该来自那里 . 请参阅the javadoc以供参考 .检查类路径中的Play jar版本 . 如果你're converting from 2.4 to 2.5, it'可能你仍然有依赖性,将Play 2.4 jar作为传递依赖 . 如果您没有使用应显示类路径的IDE,请使用工具like this one查看依赖项 .
EDIT
根据评论中给出的错误消息,您导入错误的
WSResponse
类,因为您重新导入play.api.libs.ws.WSResponse
而不是play.libs.ws.WSResponse
(请注意包的api
部分,这表示Scala API) .