我正试图在我的应用程序中覆盖Akka配置.我为应用程序创建了额外的lib,它还有application.conf文件,因为它使用了Akka.所以我有两个:
application.conf in my lib:
my-conf {
something = 1
}
application.conf in my app, which uses the lib:
something-else = "foo"
my-conf {
something = 1000
}
Run Code Online (Sandbox Code Playgroud)
当我从Intellij Idea运行应用程序时,一切都很好,并且正在覆盖lib配置.要在我的应用程序中加载配置,我正在使用简单的ConfigFactory.load()操作.但是,当我创建一个我的应用程序的jar mvn clean compile assembly:single并尝试使用此命令运行它时:java -Xmx4048m -XX:MaxPermSize=512M -Xss256K -classpath myApp.jar com.myapp.example.MyMain我收到错误:
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'something-else'
Run Code Online (Sandbox Code Playgroud)
所以我决定在我的应用程序中重命名conf文件,并以这种方式加载它:
val defConfig = ConfigFactory load
val myConfig = ConfigFactory load "myconf"
val combined = myConfig.withFallback(defConfig)
val config = ConfigFactory load combined
Run Code Online (Sandbox Code Playgroud)
它发现缺少设置,但遗憾的是我的应用程序中的配置不会覆盖我的lib中的配置.在我的lib中,我以默认方式加载配置:val settings …
是否可以在消息处理程序部分函数中保留类型信息?
我有部分函数eventHandler,它通过一些特定的参数匹配事件:
def eventHandler: Receive = {
case event: Event ?
...
val matchingReactions = projectConfiguration.reactions.filter(reaction ? reaction.eventSelector.matches(event))
Run Code Online (Sandbox Code Playgroud)
其中matches方法通过反射验证事件与一组规则:
case class EventSelector(ops: List[FieldEventSelectorOp]) {
def matches[T <: Event](event: T)(implicit tag: ru.TypeTag[T], classtag: ClassTag[T]): Boolean = {
ops.map {
op ? op.matches(event)
}.reduceLeft(_ & _)
}
}
case class FieldEventSelectorOp(field: String, operation: Symbol, value: Any) {
def matches[T <: Event](event: T)(implicit tag: ru.TypeTag[T], classtag: ClassTag[T]): Boolean = {
...
}
Run Code Online (Sandbox Code Playgroud)
所以,当我检查匹配方法中的TypeTag时,它只返回Event,而不是事件的子类 - 如何让它传递完整的类型信息?
更新:
事件的case类层次结构:
trait Event {
def eventType: String …Run Code Online (Sandbox Code Playgroud) 从Specs2迁移到Scalatest我尝试使用WordSpec,但没有运气.我已经使用了来自Testing Actor Systems的示例,但是对于我来说错误并不适合我.然后我从scaladoc复制了基本测试,仍然有同样的问题.你能指导我,我在这里做错了什么:
class MasterSpec extends WordSpec {
"A Set" when {
"empty" should {
"have size 0" in (pending)
"produce NoSuchElementException when head is invoked" in {
intercept[NoSuchElementException] {
Set.empty.head
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这给出以下错误消息:
[error] /Users/bam/Projects/ppm/core/src/test/scala/net/batyuk/ppm/core/MasterSpec.scala:12: overloaded method value in with alternatives:
[error] (testFun: () => Any)Unit <and>
[error] (testFun: MasterSpec.this.FixtureParam => Any)Unit
[error] cannot be applied to (org.scalatest.PendingNothing)
[error] "have size 0" in (pending)
[error] ^
[error] one error found
Run Code Online (Sandbox Code Playgroud)
试图转移到FunSpec,但不能强迫自己进入它,WordSpec对我来说似乎更自然