I want to get save/load my users from the database. I'm using already ReactiveMongo, in my Play app.
Most examples access the db from a controller. In order to get this working with securesocial, I'm modifying the InMemoryUserService sample from securesocial, which extends, play.api.Plugin, and not controller.
I started implementing it like this:
import play.api.Play.current
import scala.concurrent.ExecutionContext
import ExecutionContext.Implicits.global
class InMemoryUserService(application: Application) extends UserServicePlugin(application) {
val db = ReactiveMongoPlugin.db
val collection = db[JSONCollection]("users")
//...
}
But I already get a mysterious error (stack overflow) in the console:
Caused by: play.api.PlayException: Cannot load plugin[An exception occurred during Plugin [service.InMemoryUserService] initialization]
at play.api.WithDefaultPlugins$$anonfun$plugins$1$$anonfun$apply$9.apply(Application.scala:149) ~[play_2.10.jar:2.1.3]
at play.api.WithDefaultPlugins$$anonfun$plugins$1$$anonfun$apply$9.apply(Application.scala:130) ~[play_2.10.jar:2.1.3]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library.jar:na]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library.jar:na]
at scala.collection.immutable.List.foreach(List.scala:309) ~[scala-library.jar:na]
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244) ~[scala-library.jar:na]
Caused by: play.api.PlayException: Cannot load plugin[An exception occurred during Plugin [service.InMemoryUserService] initialization]
at play.api.WithDefaultPlugins$$anonfun$plugins$1$$anonfun$apply$9.apply(Application.scala:149) ~[play_2.10.jar:2.1.3]
at play.api.WithDefaultPlugins$$anonfun$plugins$1$$anonfun$apply$9.apply(Application.scala:130) ~[play_2.10.jar:2.1.3]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library.jar:na]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library.jar:na]
at scala.collection.immutable.List.foreach(List.scala:309) ~[scala-library.jar:na]
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244) ~[scala-library.jar:na]
java.lang.StackOverflowError: null
at java.io.UnixFileSystem.getBooleanAttributes0(Native Method) ~[na:1.7.0_25]
at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:242) ~[na:1.7.0_25]
at java.io.File.exists(File.java:772) ~[na:1.7.0_25]
at sun.misc.URLClassPath$FileLoader.getResource(URLClassPath.java:1072) ~[na:1.7.0_25]
at sun.misc.URLClassPath$FileLoader.findResource(URLClassPath.java:1039) ~[na:1.7.0_25]
at sun.misc.URLClassPath$1.next(URLClassPath.java:226) ~[na:1.7.0_25]
In the webpage the stacktrace looks a bit different - although the message is also not very informative:
"An exception occurred during Plugin [service.InMemoryUserService] initialization"
But it points to the causing line:
play.api.Application$class.plugin(Application.scala:235)
play.api.DefaultApplication.plugin(Application.scala:383)
play.modules.reactivemongo.ReactiveMongoPlugin$.current(ReactiveMongoPlugin.scala:79)
play.modules.reactivemongo.ReactiveMongoPlugin$.db(ReactiveMongoPlugin.scala:76)
service.InMemoryUserService.<init>(InMemoryUserService.scala:33)
which is:
val db = ReactiveMongoPlugin.db
What's happening? Am I not supposed to access the db from this class? If not, how do I use Mongo to store my users with securesocial?
Thanks in advance.