我正在使用SBT + Idea 13.1.1,我的所有SBT文件都是红色的:
name := "Transformer"
version := "1.0"
libraryDependencies ++= Seq(
"com.github.scopt" %% "scopt" % "3.2.0",
"org.scalatest" % "scalatest_2.10" % "2.1.0" % "test"
)
Run Code Online (Sandbox Code Playgroud)
它说的是"无法解析符号..."的名称或版本......但是Seq还可以.
但是从SBT cmd运行应用程序,甚至直接运行主要或scalatests的Idea都是很好的.
我知道排除故障的信息并不多,但我不知道要检查什么.告诉我,如果你有一个想法,我会提供一切.
干杯
'play eclipsify'之后,项目文件夹中没有eclipse文件夹.如何调试这个项目使用eclipse与JPDA?
我试图理解我在下面看到的错误,并学习如何解决它.
could not find implicit value for parameter materializer: akka.Stream.Materializer
val fut: Future[Result] = action.apply(fakeRequest).run
^
not enough arguments for method run (implicit materializer: akka.stream.Materializer)scala.concurrent.Future[play.api.mvc.Result].
Unspecified value parameter materializer.
val fut: Future[Result] = action.apply(fakeRequest).run
^
Run Code Online (Sandbox Code Playgroud)
以下是产生错误的测试代码:
package com.foo.test
import com.foo.{Api, BoundingBox}
import org.scalatest.{FlatSpec, Matchers}
import play.api.libs.json._
import play.api.mvc._
import play.api.test.{FakeHeaders, FakeRequest}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
class TestJmlPlay extends FlatSpec with Matchers {
val bbox = new BoundingBox(-76.778154438007732F, 39.239828198015971F, -76.501003519894326F, 39.354663763993926F)
"latitudes" should "be between swLat and neLat" in { …Run Code Online (Sandbox Code Playgroud) 假设我想要一个带有字段,电子邮件的表格,只有在他们没有输入电话号码时才需要.此外,只有在他们没有收到电子邮件时才需要电话号码,我该怎么办?做这个?
如果需要NoValid,我想做这样的事情.
import play.api.data._
import play.api.data.Forms._
import play.api.data.validation.Constraints._
case class User(email: Option[String] = None, age: Option[Int])
val userForm = Form(
mapping(
"email" -> email.verifying(requiredNoValid(phoneNumber)),
"phoneNumber" -> number.verifying(requiredNoValid(email))
)(User.apply)(User.unapply)
)
Run Code Online (Sandbox Code Playgroud)
我已经在Play 1.X中为此构建了自己的解决方案,但我想放弃其中的大部分内容并使用Play 2表单为我执行此操作,如果功能在那里或者是否有办法通过实现验证器或约束.
我习惯于在Ruby on Rails项目上工作,并rails console在做任何其他事情之前使用命令来测试我的所有模型.我最近切换到了Play Framework 2.4.x,因为在我工作的地方做了一些选择.
我正在寻找相当于这个控制台,用我在application.conf(db.default.url)中提供的数据库测试我的模型.我怎样才能做到这一点 ?
小奖金问题:如果它存在,有没有办法将它与IntelliJ集成?
我正在使用Play 2.5构建一个简单的应用程序.为了获得更好的性能,我使用了Akka chunked响应和Java 8 CompletionStage策略.下面是生成分块响应的代码(不使用ComperableFuture时工作正常):
@Singleton
public class AbstractSource {
public Source<ByteString, ?> getChunked(String html) {
return Source.<ByteString>actorRef(256, OverflowStrategy.dropNew())
.mapMaterializedValue(sourceActor -> {
sourceActor.tell(ByteString.fromString(html), null);
sourceActor.tell(new Status.Success(NotUsed.getInstance()), null);
return null;
});
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
@Singleton
@AddCSRFToken
public class Application extends Controller {
@Inject
private AbstractSource abstractSource;
public CompletionStage<Result> index() {
CompletionStage<Source<ByteString, ?>> source = CompletableFuture.supplyAsync(() ->
abstractSource.getChunked(index.render(CSRF.getToken(request()).map(t ->
t.value()).orElse("no token")).body()
)
);
return source.thenApply( chunks -> ok().chunked(chunks));
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我运行应用程序时,它会抛出以下异常:
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[CompletionException: java.lang.RuntimeException: There is no HTTP Context available from …Run Code Online (Sandbox Code Playgroud) 我在Scala中有这个控制器:
def commonRedirect(anId: Long) = {
implicit val aRule = CommonClient.getTheRule(anId)
aRule match {
case false ? Redirect("/general-rule/" + anId)
case true ? Redirect("/custom-rule/" + anId)
}
Run Code Online (Sandbox Code Playgroud)
}
但是,这导致错误:"无法使用返回play.api.mvc.Result作为请求处理程序的方法".
如果我应用动作生成器,它可以工作,但这不是我想要的方式.
有什么想法解决这个问题?
谢谢.
我正在将Scala Play应用程序迁移到2.5,并且我正在将我的组件移动到依赖注入.还有一个地方我不知道如何去做.我在随播对象中定义了一个PathBindable隐式转换:
object Task {
implicit def pathBindable(implicit stringBinder: PathBindable[String]) =
new PathBindable[Task] {
...
}
}
Run Code Online (Sandbox Code Playgroud)
PathBindable的实现需要从存储库中查找对象,但我还没有找到一种依赖注入存储库的方法.作为一种解决方法,我正在使用现已弃用的Play对象:
val tasks = Play.application(Play.current).injector.instanceOf[TasksRepository]
Run Code Online (Sandbox Code Playgroud)
任何想法如何妥善解决?
dependency-injection scala playframework playframework-2.0 playframework-2.5
我正在讨论如何配置我的Play 2.0应用程序,以便在数据库演进和运行时都不使用如此多的数据库连接.我在小组和IRC中问过这个没有运气的.
我正在使用cleardb点燃实例(max_user_connections = 10)和heroku ...
基本上当我尝试在我的Play 2.0应用程序上运行数据库演变时,我得到:
! @6a2mjd7kg - Internal server error, for request [GET /] ->
play.api.db.evolutions.InvalidDatabaseRevision: Database 'default' needs evolution! [An SQL script need to be run on your database.]
at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:424) ~[play_2.9.1.jar:2.0]
at play.api.db.evolutions.EvolutionsPlugin$$anonfun$onStart$1.apply(Evolutions.scala:410) ~[play_2.9.1.jar:2.0]
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59) ~[scala-library.jar:0.11.2]
at scala.collection.immutable.List.foreach(List.scala:45) ~[scala-library.jar:0.11.2]
at play.api.db.evolutions.EvolutionsPlugin.onStart(Evolutions.scala:410) ~[play_2.9.1.jar:2.0]
at play.api.Play$$anonfun$start$1.apply(Play.scala:60) ~[play_2.9.1.jar:2.0]
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms and trying again. Attempts left: 10. Exception: null
[error] c.j.b.h.AbstractConnectionHook - Failed to acquire connection Sleeping for 1000ms …Run Code Online (Sandbox Code Playgroud) 我正在使用Play with Scala,我正在尝试创建一个单例,我想从它的特性而不是直接注入它.
例如:
@ImplementedBy(classOf[S3RepositoryImpl])
trait S3Repository {
}
@Singleton
class S3RepositoryImpl extends S3Repository {
}
Run Code Online (Sandbox Code Playgroud)
但这失败了,错误:
特质是单身是抽象的; 无法实例化
我尝试了几种组合,它们都产生了相同的效果.
我来自春天的背景,它很自然吗?我错过了Guice如何处理这种类型的注射剂吗?
谢谢.
scala ×5
sbt ×2
akka ×1
akka-stream ×1
eclipse ×1
guice ×1
heroku ×1
java ×1
mysql ×1
validation ×1