首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在涉及默认参数的应用程序中无法找到SttpBackends +“错误”。

在涉及默认参数的应用程序中无法找到SttpBackends +“错误”。
EN

Stack Overflow用户
提问于 2020-11-11 07:25:20
回答 1查看 258关注 0票数 0

我正在使用bot4s在Scala中创建一个非常简单的电报机器人。我在很大程度上遵循了这个例子。这是代码

代码语言:javascript
复制
package info.jjmerelo.BoBot

import cats.instances.future._
import cats.syntax.functor._

import com.bot4s.telegram.api.RequestHandler
import com.bot4s.telegram.api.declarative.Commands
import com.bot4s.telegram.clients.{FutureSttpClient, ScalajHttpClient}
import com.bot4s.telegram.future.{Polling, TelegramBot}

import scala.util.Try
import scala.concurrent.Future

import com.typesafe.scalalogging.Logger


object BoBot extends TelegramBot
    with Polling
    with Commands[Future] {

  implicit val backend = SttpBackends.default
  def token = sys.env("BOBOT_TOKEN")
  override val client: RequestHandler[Future] = new FutureSttpClient(token)
  val log = Logger("BoBot")
//  val lines = scala.io.Source.fromFile("hitos.json").mkString
//  val hitos = JSON.parseFull( lines )
//  val solo_hitos = hitos.getOrElse( hitos )

  onCommand("hey") { implicit msg =>
    log.info("Hello")
    reply("Conseguí que funcionara").void
  }
}

这是build.sbt

代码语言:javascript
复制
name := "bobot"

version := "0.0.1"

organization := "info.jjmerelo"

libraryDependencies += "com.bot4s" %% "telegram-core" % "4.4.0-RC2"

val circeVersion = "0.12.3"

libraryDependencies ++= Seq(
  "io.circe" %% "circe-core",
  "io.circe" %% "circe-generic",
  "io.circe" %% "circe-parser"
).map(_ % circeVersion)

libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.2"
retrieveManaged := true

切尔斯要晚些时候

无论如何,我成功地编译了其中的大部分,但我仍然得到以下两个错误:

代码语言:javascript
复制
[info] compiling 2 Scala sources to /home/jmerelo/Asignaturas/cloud-computing/BoBot/target/scala-2.12/classes ...
[error] /home/jmerelo/Asignaturas/cloud-computing/BoBot/src/main/scala/info/jjmerelo/BoBot.scala:21:26: not found: value SttpBackends
[error]   implicit val backend = SttpBackends.default
[error]                          ^
[error] /home/jmerelo/Asignaturas/cloud-computing/BoBot/src/main/scala/info/jjmerelo/BoBot.scala:23:49: could not find implicit value for parameter backend: com.softwaremill.sttp.SttpBackend[scala.concurrent.Future,Nothing]
[error] Error occurred in an application involving default arguments.
[error]   override val client: RequestHandler[Future] = new FutureSttpClient(token)
[error]                                                 ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 5 s, completed 11 nov. 2020 8:19:38

我搞不清这两个人中的任何一个。SttpBackends是缺失的,这很明显,但是在这个示例中没有任何东西表明它是需要的,或者,在这个问题上,应该包括什么库。第二个是关于默认参数的,即使我将token定义为String,或者如果我将def更改为val,我也无法理解它。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-11 13:25:57

您的错误消息是相互关联的。第一个错误告诉我们,编译器无法找到具有SttpBackend字段的对象SttpBackend。第二个例子告诉我们,编译器无法找到用于构造implicit backend: SttpBackendFutureSttpClient。它需要两个提示:SttpBackendExecutionContext

代码语言:javascript
复制
class FutureSttpClient(token : _root_.scala.Predef.String, 
  telegramHost : _root_.scala.Predef.String = { /* compiled code */ })
  (implicit backend : com.softwaremill.sttp.SttpBackend[scala.concurrent.Future, scala.Nothing], 
    ec : scala.concurrent.ExecutionContext) 
  extends com.bot4s.telegram.clients.SttpClient[scala.concurrent.Future] {...}

您可以像在bot4s实例中那样自己创建它。

如果您尝试在bot4s库中找到bot4s对象,您将在bot4s实例中找到以下代码

代码语言:javascript
复制
import com.softwaremill.sttp.okhttp._

object SttpBackends {
  val default: SttpBackend[Future, Nothing] = OkHttpFutureBackend()
}

将此对象添加到项目中以使其可编译。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64782138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档