resilva87
resilva87

Reputation: 3465

Getting ebean datasource configuration right with Play! 2

Firstly, the relevant configuration that I've set in my current application.conf, which is actually pretty much defined in the Java/Scala Ebean documentation from Play:

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.user="sa"
db.default.password=""
ebean.default="models.*"

I am running Play Framework 2.0.4

After poking around with Play, I wrote a couple of integration tests for my sample app. Found this nice example on how to use Ebean to generate ddl code for my model and decided to give it a try but it seems that my Ebean configuration is missing something.

My code pretty much follows the example above, but it is Scala:

def setUp = {
    val server = Ebean.getServer("default")
    ...
    val ddl = new DdlGenerator(server.asInstaceOf[SpiEbeanServer], new H2Platform, config)
    ...
}

Calling Ebean.getServer("default") throws this exception: Could not create an instance of MyClassSpec caused by java.lang.RuntimeException: DataSource user is null?

Hm, maybe I got something wrong but I believed that the db.default.* properties had already set whatever Ebean needed.

I am too refering the same datasource name ("default") in both my application and Ebean and my test code is defined inside a running(FakeApplication(additionalConfiguration = inMemoryDatabase("default"))) code block.

Is there anything more to configure? Thank you!

Upvotes: 3

Views: 5449

Answers (1)

resilva87
resilva87

Reputation: 3465

Well, I made it work with the ebean.properties file as described here.

datasource.default=default

datasource.default.username=sa  
datasource.default.password=  
datasource.default.databaseUrl=jdbc:h2:mem:tests;DB_CLOSE_DELAY=-1  
datasource.default.databaseDriver=org.h2.Driver  
datasource.default.minConnections=1  
datasource.default.maxConnections=25  
datasource.default.heartbeatsql=select 1  
datasource.default.isolationlevel=read_committed  

So my database (ebean) related configuration is set in another file, with actually needing to be defined ebeans.default="models.*" in application.conf and ebeanEnabled := true in Build.scala

Hope it helps someone too!

Upvotes: 1

Related Questions