0

我已在我的应用程序中将播放框架更新为 2.1 版,但它不再工作了。

这是一个简单的控制器:

package controllers

import play.api._
import play.api.mvc._
import models.Country
import ru.circumflex.orm._

object Application extends Controller {

  def index = Action {

      val co = Country AS "co"
      val q = SELECT (co.*) FROM (co)

      val countries: Seq[Country] = q.list()

      Ok(views.html.index(countries))
  }

}

这是一个国家的模型:

package models

import ru.circumflex.orm.{TextField, Table, Record}
import java.util.regex.Pattern

class Country extends Record[String, Country] {
  def PRIMARY_KEY = code
  def relation = Country

  def this(code: String, name: String) = {
    this()
    this.code := code
    this.name := name
  }

  val code: TextField[Country] = "code".VARCHAR(2).NOT_NULL
  val name = "name".TEXT.NOT_NULL

  def cities = inverseMany(City.country)

  override def toString = name.getOrElse("unknow")
}

object Country extends Country with Table[String, Country] {
  val codeKey = UNIQUE(code)
  val codeChk = CONSTRAINT("code_chk").CHECK("code IN ('ch', 'us', 'uk', 'fr', 'es', 'it', 'pt', 'by')")
  val idx = "country_code_idx".INDEX("LOWER(code)").USING("btree").UNIQUE

  validation.notNull(_.code)
            .notEmpty(_.code)
            .pattern(_.code, Pattern.compile("(?i:[a-z]{2})"))
}

打开页面时出现以下错误:

[error] application -                                                                            

! @6d9l5j0i0 - Internal server error, for (GET) [/] ->                                           

play.api.Application$$anon$1: Execution exception[[RuntimeException: java.lang.ExceptionInInitial
izerError]]                                                                                      
        at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.0]  
        at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.0]  
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$24.apply(
PlayDefaultUpstreamHandler.scala:314) [play_2.10.jar:2.1.0]                                      
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$24.apply(
PlayDefaultUpstreamHandler.scala:312) [play_2.10.jar:2.1.0]                                      
        at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play
_2.10.jar:2.1.0]                                                                                 
        at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play
_2.10.jar:2.1.0]                                                                                 
java.lang.RuntimeException: java.lang.ExceptionInInitializerError                                
        at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:222) ~[play_2.10.jar:2.1.0]     
        at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$
6.apply(Action.scala:109) ~[play_2.10.jar:2.1.0]                                                 
        at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$
6.apply(Action.scala:109) ~[play_2.10.jar:2.1.0]                                                 
        at play.utils.Threads$.withContextClassLoader(Threads.scala:18) ~[play_2.10.jar:2.1.0]   
        at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5.apply(Action.sc
ala:108) ~[play_2.10.jar:2.1.0]                                                                  
        at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5.apply(Action.sc
ala:106) ~[play_2.10.jar:2.1.0]                                                                  
Caused by: java.lang.ExceptionInInitializerError: null                                           
        at controllers.Application$$anonfun$index$1.apply(Application.scala:18) ~[na:na]         
        at controllers.Application$$anonfun$index$1.apply(Application.scala:11) ~[na:na]         
        at play.api.mvc.ActionBuilder$$anonfun$apply$11.apply(Action.scala:254) ~[play_2.10.jar:2
.1.0]                                                                                            
        at play.api.mvc.ActionBuilder$$anonfun$apply$11.apply(Action.scala:254) ~[play_2.10.jar:2
.1.0]                                                                                            
        at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:217) ~[play_2.10.jar:2.1.0]     
        at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$2$$anonfun$apply$5$$anonfun$apply$
6.apply(Action.scala:109) ~[play_2.10.jar:2.1.0]                                                 
Caused by: java.lang.ClassNotFoundException: models.Country                                      
        at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.7.0_09]                          
        at java.net.URLClassLoader$1.run(Unknown Source) ~[na:1.7.0_09]                          
        at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_09]             
        at java.net.URLClassLoader.findClass(Unknown Source) ~[na:1.7.0_09]                      
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_09]                        
        at java.lang.ClassLoader.loadClass(Unknown Source) ~[na:1.7.0_09]                        

谁能帮我解决这个问题?

4

2 回答 2

0

Circumflex 2.x 似乎不是针对 scala 2.10 构建的(play 2.1 需要它)。

circumflex 3.0 是在 2.10 中构建的,但目前仅在快照中。您可以在此处获取快照:

https://oss.sonatype.org/content/repositories/snapshots/

请注意,包名称已从ru.circumflex更改为pro.savant.circumflex ,因此您可能需要重构导入语句。

于 2013-03-18T02:31:25.120 回答
0

我使用以下信息修复了它:参考

首先从 Github 获取上一个版本的circumflex:

git clone git://github.com/inca/circumflex.git

按照建议,更改文件 orm/src/main/scala/relation.scala 中的行

第 55 行:

val _recordClass: Class[R] = Class.forName(

val _recordClass: Class[R] = this.getClass().getClassLoader().loadClass(

现在我们可以在 Play 2.1 App 中编译、安装和使用它了

cd circumflex
mvn clean install

如果您只需要一个模块:

cd circumflex
mvn clean install -pl <circumflex-orm> -am

现在编辑您的project/Build.scala文件以添加依赖项和本地代表

  val appDependencies = Seq(    
   "pro.savant.circumflex" % "circumflex-orm" % "3.1-SNAPSHOT"
  )

  val main = play.Project(appName, appVersion, appDependencies).settings(defaultScalaSettings:_*).settings(
    resolvers += "Local Maven Repository" at "file:"+Path.userHome.absolutePath+"/.m2/repository"
  )
于 2013-05-23T00:19:01.783 回答