使用Play2的Spring Scala:对象springframework不是包org的成员

时间:2015-02-26 20:42:28

标签: spring scala playframework-2.0 sbt

我是scala的新手,我正在尝试在简单的helloWorld scala-play应用程序中使用Spring Scala作为di框架。根据这篇文章,我把Global对象放到了应用程序的根目录中。 https://www.playframework.com/documentation/2.1.x/ScalaDependencyInjection

这是我的全局对象:

import org.springframework.context.annotation.AnnotationConfigApplicationContext

object Global extends play.api.GlobalSettings {

  private val context = new AnnotationConfigApplicationContext()

  override def getControllerInstance[A](controllerClass: Class[A]): A = {
    context.getBean(controllerClass)
  }
}

和sbt文件:

name := """test"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.1"

resolvers += "SpringSource Milestone Repository" at "http://repo.springsource.org/milestone"

libraryDependencies ++= Seq(
  jdbc,
  anorm,
  cache,
  ws,
  "org.springframework.scala" % "spring-scala" % "1.0.0.M1"
)

有了这些东西,我得到了一个例外:

play.PlayExceptions$CompilationException: Compilation error[object springframework is not a member of package org]
    at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
    at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
    at scala.Option.map(Option.scala:145) ~[scala-library-2.11.1.jar:na]

据我所知,谷歌搜索后可能是因为默认包和相对导入,但它对我没有多大帮助,因为建议的解决方案,如春季包之前的_root_,不起作用。你能告诉我我做错了吗?

0 个答案:

没有答案