mathieuancelin / play2-couchbase

Couchbase plugin for Play framework 2.2 with reactive API
http://reactivecouchbase.org/
19 stars 8 forks source link

Trouble reading conf [Bucket 'bucketname' is not defined] #29

Closed arcane86 closed 11 years ago

arcane86 commented 11 years ago

Hi,

i'm starting a new Play 2.2.0 application and i'm getting an error at launch from Couchbase plugin.

Here my build.sbt:

name := "name"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  cache,
  "securesocial" %% "securesocial" % "master-SNAPSHOT",
  "org.ancelin.play2.couchbase" %% "play2-couchbase" % "0.6-SNAPSHOT"
)

resolvers ++= Seq(
  Resolver.url("sbt-plugin-snapshots", new URL("http://repo.scala-sbt.org/scalasbt/sbt-plugin-snapshots/"))(Resolver.ivyStylePatterns),
  "ancelin" at "https://raw.github.com/mathieuancelin/play2-couchbase/master/repository/snapshots",
  "Spy Repository" at "http://files.couchbase.com/maven2"
)

play.Project.playScalaSettings

I import the Couchbase conf into my application.conf:

include "couchbase.conf"

The couchbase.conf:

couchbase {
    execution-context {
        timeout=1000
        pollfutures=true
        polldelay=10
        execution-context {
            fork-join-executor {
                parallelism-factor = 20.0
                parallelism-max = 200
            }
        }
    }

    buckets = [{
        host="clevercloud couch service 1 url"
        port="8091"
        base="pools"
        bucket="bucketname1"
        user="user1"
        pass="pass1"
        timeout="0"
    }, {
        host="clevercloud couch service 2 url"
        port="8091"
        base="pools"
        bucket="bucketname2"
        user="user2"
        pass="pass2"
        timeout="0"
    }]
}

I currently have only one CouchbaseCrudSourceController:

case class User(idKey: String,
                secureSocialUser: SecureSocialUser)
...
object UserDAO extends CouchbaseCrudSourceController[User] {

    val bucket = Couchbase.bucket("bucketname1")

    override def idKey = "idKey"
}

The play run command give me nothing special, but when I try and go to index (or any page), I got that:

play.api.UnexpectedException: Unexpected exception[ExceptionInInitializerError: null]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:152) ~[play_2.10.jar:2.2.0]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.0]
    at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:112) ~[play_2.10.jar:2.2.0]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:110) ~[play_2.10.jar:2.2.0]
    at scala.util.Success.flatMap(Try.scala:200) ~[scala-library.jar:na]
Caused by: java.lang.ExceptionInInitializerError: null
    at Routes$.setPrefix(routes_routing.scala:21) ~[na:na]
    at play.api.Application$$anonfun$loadRoutes$3.apply(Application.scala:247) ~[play_2.10.jar:2.2.0]
    at play.api.Application$$anonfun$loadRoutes$3.apply(Application.scala:246) ~[play_2.10.jar:2.2.0]
    at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
    at play.api.Application$class.loadRoutes(Application.scala:246) ~[play_2.10.jar:2.2.0]
    at play.api.DefaultApplication.loadRoutes(Application.scala:399) ~[play_2.10.jar:2.2.0]
Caused by: play.api.PlayException: Error with bucket bucketname1[Bucket 'bucketname1' is not defined]
    at org.ancelin.play2.couchbase.Couchbase$$anonfun$bucket$1.apply(Couchbase.scala:50) ~[play2-couchbase_2.10-0.6-SNAPSHOT.jar:0.6-SNAPSHOT]
    at org.ancelin.play2.couchbase.Couchbase$$anonfun$bucket$1.apply(Couchbase.scala:50) ~[play2-couchbase_2.10-0.6-SNAPSHOT.jar:0.6-SNAPSHOT]
    at scala.Option.getOrElse(Option.scala:120) ~[scala-library.jar:na]
    at org.ancelin.play2.couchbase.Couchbase$.bucket(Couchbase.scala:50) ~[play2-couchbase_2.10-0.6-SNAPSHOT.jar:0.6-SNAPSHOT]
    at models.UserDAO$.<init>(User.scala:46) ~[na:na]
    at models.UserDAO$.<clinit>(User.scala) ~[na:na]

I tried to debug a bit and the CouchBasePlugin buckets Map is empty, but I don't understand why.

arcane86 commented 11 years ago

Ok now i'm ashamed :/ !

The problem came from my CouchbaseCrudSourceController. I was using val bucket = Couchbase.bucket("b6a63i04635tc7me") instead of `def bucket = Couchbase.bucket("b6a63i04635tc7me")``.

mathieuancelin commented 11 years ago

It happens ;-)

mathieuancelin commented 11 years ago

You can also use lazy val bucket = ...