読者です 読者をやめる 読者になる 読者になる

LiftのORMをmainメソッドから使う方法

WEBアプリを起動しないで、LiftのORMを使いたい場合には、ORMのメソッドを使う前にBoot.bootを実行しておけば使えるようになる。

サンプル

  import bootstrap.liftweb._

  def main(args: Array[String]) = {
    val boot = new Boot
    boot.boot

bootしない場合のエラー内容

Exception in thread "main" java.lang.NullPointerException: Looking for Connection Identifier DefaultConnectionIdentifier but failed to find either a JNDI data source with the name lift or a lift connection manager with the correct name
	at net.liftweb.mapper.DB$$anonfun$3$$anonfun$apply$5.apply(DB.scala:74)
	at net.liftweb.mapper.DB$$anonfun$3$$anonfun$apply$5.apply(DB.scala:74)
	at net.liftweb.util.EmptyCan.openOr(Can.scala:308)
	at net.liftweb.mapper.DB$$anonfun$3.apply(DB.scala:74)
	at net.liftweb.mapper.DB$$anonfun$3.apply(DB.scala:74)
	at net.liftweb.util.EmptyCan.openOr(Can.scala:308)
	at net.liftweb.mapper.DB$.newConnection(DB.scala:70)
	at net.liftweb.mapper.DB$.getConnection(DB.scala:87)
	at net.liftweb.mapper.DB$.use(DB.scala:241)
	at net.liftweb.mapper.MetaMapper$class.save(MetaMapper.scala:406)
	at com.yuroyoro.lift.crudsample.model.LCategory$.save(LCategory.scala:12)
	at net.liftweb.mapper.Mapper$$anonfun$save$1.apply(Mapper.scala:66)
	at net.liftweb.mapper.Mapper$$anonfun$save$1.apply(Mapper.scala:66)
	at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:24)
	at net.liftweb.mapper.Safe$.runSafe(Safe.scala:34)
	at net.liftweb.mapper.Mapper$class.runSafe(Mapper.scala:33)
	at com.yuroyoro.lift.crudsample.model.LCategory.runSafe(LCategory.scala:16)
	at net.liftweb.mapper.Mapper$class.save(Mapper.scala:65)
	at com.yuroyoro.lift.crudsample.model.LCategory.save(LCategory.scala:16)
	at com.yuroyoro.lift.crudsample.autogen.CreateCategories$$anonfun$create$1.apply(CreateCategories.scala:130)
	at com.yuroyoro.lift.crudsample.autogen.CreateCategories$$anonfun$create$1.apply(CreateCategories.scala:127)
	at scala.Iterator$class.foreach(Iterator.scala:414)
	at scala.Iterator$$anon$2.foreach(Iterator.scala:265)
	at scala.Iterable$class.foreach(Iterable.scala:256)
	at scala.collection.mutable.HashMap.foreach(HashMap.scala:33)
	at com.yuroyoro.lift.crudsample.autogen.CreateCategories.create(CreateCategories.scala:127)
	at com.yuroyoro.lift.crudsample.autogen.hogehoge$.main(CreateCategories.scala:23)
	at com.yuroyoro.lift.crudsample.autogen.hogehoge.main(CreateCategories.scala)