如何在scala主对象中使用幻像

时间:2017-03-28 03:20:34

标签: scala cassandra phantom-dsl

我正在尝试使用幻影来处理我的Cassandra 这是我学习如何使用幻影的例子(感谢Thiago)

https://github.com/iamthiago/cassandra-phantom

我可以成功运行'SongTest'。

但是在我的scala主对象中运行database.create时遇到了一些麻烦。 'scalatest'中的相同代码成功运行。但是在我的scala主对象中,它失败了。 这是我的源代码

package com.cassandra.phantom.modeling

import com.cassandra.phantom.modeling.database._
import com.cassandra.phantom.modeling.connector._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
/**
  * Created by karamko on 2017. 3. 28..
  */

class TestCass extends EmbeddedDatabase with Connector.connector.Connector {
  def create() {
    database.create(5.seconds)
  }
}

object Main extends App{
  val test = new TestCass
  test.create()
}

这是我的错误

Exception in thread "main" java.lang.NoClassDefFoundError: scala/reflect/runtime/package$
    at com.outworkers.phantom.column.AbstractColumn$class.com$outworkers$phantom$column$AbstractColumn$$_name(AbstractColumn.scala:55)
    at com.outworkers.phantom.column.Column.com$outworkers$phantom$column$AbstractColumn$$_name$lzycompute(Column.scala:24)
    at com.outworkers.phantom.column.Column.com$outworkers$phantom$column$AbstractColumn$$_name(Column.scala:24)
    at com.outworkers.phantom.column.AbstractColumn$class.name(AbstractColumn.scala:58)
    at com.outworkers.phantom.column.Column.name(Column.scala:24)
    at com.outworkers.phantom.column.PrimitiveColumn.qb(PrimitiveColumn.scala:38)
    at com.outworkers.phantom.builder.query.RootCreateQuery$$anonfun$lightweight$1.apply(CreateQuery.scala:48)
    at com.outworkers.phantom.builder.query.RootCreateQuery$$anonfun$lightweight$1.apply(CreateQuery.scala:48)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
    at scala.collection.immutable.Set$Set4.foreach(Set.scala:200)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
    at scala.collection.AbstractSet.scala$collection$SetLike$$super$map(Set.scala:47)
    at scala.collection.SetLike$class.map(SetLike.scala:92)
    at scala.collection.AbstractSet.map(Set.scala:47)
    at com.outworkers.phantom.builder.query.RootCreateQuery.lightweight(CreateQuery.scala:48)
    at com.outworkers.phantom.builder.query.RootCreateQuery.ifNotExists(CreateQuery.scala:71)
    at com.outworkers.phantom.CassandraTable.autocreate(CassandraTable.scala:92)
    at com.cassandra.phantom.modeling.database.SongsDatabase$$anon$1$$anonfun$createQueries$1.apply(SongsDatabase.scala:15)
    at com.cassandra.phantom.modeling.database.SongsDatabase$$anon$1$$anonfun$createQueries$1.apply(SongsDatabase.scala:15)
    at com.outworkers.phantom.database.ExecutableCreateStatementsList.future(Database.scala:173)
    at com.outworkers.phantom.database.Database.createAsync(Database.scala:85)
    at com.outworkers.phantom.database.Database.create(Database.scala:75)
    at com.cassandra.phantom.modeling.SongsStreaming$.main(Main.scala:29)
    at com.cassandra.phantom.modeling.SongsStreaming.main(Main.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: scala.reflect.runtime.package$
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 30 more

1 个答案:

答案 0 :(得分:1)

我解决了我的问题,添加以下依赖

libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value

非常感谢