播放2.6.x项目中不存在包play.libs.ws

时间:2018-07-02 13:10:50

标签: java playframework

我在项目的ws中添加了build.sbt依赖性,但是在编译时我得到的软件包play.libs.ws不存在。

下面是build.sbt,控制器和sbt编译命令上的错误消息的屏幕截图。

build.sbt

name := """tools-server"""
organization := "com.example"

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.12.4"

libraryDependencies += guice

libraryDependencies ++= Seq(
  ws
)

我的控制器

package controllers;

import play.libs.ws.WSClient;
import play.mvc.*;

import javax.inject.Inject;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.CompletionStage;


public class HomeController extends Controller {

    private final WSClient ws;

    @Inject
    HomeController(WSClient ws) {
        this.ws = ws;
    }

    public CompletionStage<Result> index(String url) {
        CompletionStage<? extends Integer> respPromise = this.sendHttpRequest(url);

        return respPromise.thenApply(resp -> ok(resp.toString()));
    }


    private CompletionStage<? extends Integer> sendHttpRequest(String url) {
        return this.ws.url(url).setRequestTimeout(Duration.of(10000, ChronoUnit.MILLIS)).get().thenApply(resp -> resp.getStatus());
    }
}

这是我在编译sbt时遇到的错误。

play.sbt.PlayExceptions$CompilationException: Compilation error[package play.libs.ws does not exist]
        at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:34)
        at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:34)
        at scala.Option.map(Option.scala:146)
        at play.sbt.run.PlayReload$.$anonfun$taskFailureHandler$1(PlayReload.scala:33)
        at scala.Option.map(Option.scala:146)
        at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:28)
        at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:24)
        at play.sbt.run.PlayReload$.$anonfun$compile$3(PlayReload.scala:51)
        at scala.util.Either$LeftProjection.map(Either.scala:573)

0 个答案:

没有答案