cant inject使用macwire播放WS或WSClient

时间:2015-01-10 14:55:51

标签: scala dependency-injection playframework-2.0

这是我想要做的事情

package gc.services.http.playWs.lmi

import com.softwaremill.macwire.Macwire
import play.api.Play.current
import play.api.libs.ws._
import play.api.libs.ws.ning.NingAsyncHttpClientConfigBuilder
import scala.concurrent.Future
import play.api.libs.ws.{WSResponse, WSRequestHolder, WSClient}

import scala.concurrent.Future

class LmiWs extends Macwire{
  val baseUrl = "http://api.lmiforall.org.uk/api/v1"
  //inject plays ws client
  lazy val http = wire[WSClient]

  def getRequestHolder(url: String = baseUrl): WSRequestHolder = {
    http.url(url)
  }

  def get(request: WSRequestHolder): Future[WSResponse] = {
    request.get()
  }
}

如果我尝试连线[WS] IntelliJ给出无法解析符号。 IntelliJ中没有显示上述错误,但在编译mac wire throws

  

找不到WeakTypeTag的构造函数[play.api.libs.ws.WSClient]

这个类只是为我想要命中的应用程序定义基本路由,并且它将针对每个特定路由扩展一些不同的类。我希望能够模拟WS依赖关系,这样当我测试这个和后代类时,我可以这样做,而无需发送实际的HTTP请求。

1 个答案:

答案 0 :(得分:0)

也许你可以试试这个:

  lazy val http: WSClient = WS.client