playframework - Prepare multi-databases with play framework -
i want prepare application compatible many databases types. try i've used h2, mysql , postgresql. 'ive added build.sbt :
"mysql" % "mysql-connector-java" % "5.1.35", "org.postgresql" % "postgresql" % "9.4-1201-jdbc41"
and i've added conf/prod.conf configuration without database configuration, , 3 files: conf/h2.conf
include "prod.conf" db.h2.driver=org.h2.driver db.h2.url="jdbc:h2:mem:dontforget" db.h2.jndiname=defaultds ebean.h2="fr.chklang.dontforget.business.*"
conf/mysql.conf
include "prod.conf" db.mysql.driver=com.mysql.jdbc.driver db.mysql.jndiname=defaultds ebean.mysql="fr.chklang.dontforget.business.*"
conf/postgresql.conf
include "prod.conf" db.postgresql.driver=org.postgresql.driver db.postgresql.jndiname=defaultds ebean.postgresql="fr.chklang.dontforget.business.*"
add i've 3 folders conf/evolutions with
- evolutions/h2
- evolutions/mysql
- evolutions/postgresql
with these things user can start application command :
-dconfig.file=dontforget-conf.conf -dapplyevolutions.default=true -dhttp.port=10180 &
and conf file is
include "postgresql.conf" db.postgresql.url="jdbc:postgresql:dontforget" db.postgresql.user=myusername db.postgresql.password=mypassword
but configuration, when application try connect db : default ebeanserver has not been defined? set via ebean.datasource.default property. otherwise should registered programatically via registerserver()]]
so i've tried add, configuration :
ebean.datasource.default=postgresql
but when add i've :
configuration error: configuration error[configuration error[]] @ play.api.configuration$.play$api$configuration$$configerror(configuration.scala:94) @ play.api.configuration.reporterror(configuration.scala:743) @ play.configuration.reporterror(configuration.java:310) @ play.db.ebean.ebeanplugin.onstart(ebeanplugin.java:56) @ play.api.play$$anonfun$start$1$$anonfun$apply$mcv$sp$1.apply(play.scala:91) @ play.api.play$$anonfun$start$1$$anonfun$apply$mcv$sp$1.apply(play.scala:91) @ scala.collection.immutable.list.foreach(list.scala:383) @ play.api.play$$anonfun$start$1.apply$mcv$sp(play.scala:91) @ play.api.play$$anonfun$start$1.apply(play.scala:91) @ play.api.play$$anonfun$start$1.apply(play.scala:91) @ play.utils.threads$.withcontextclassloader(threads.scala:21) @ play.api.play$.start(play.scala:90) @ play.core.staticapplication.<init>(applicationprovider.scala:55) @ play.core.server.nettyserver$.createserver(nettyserver.scala:253) @ play.core.server.nettyserver$$anonfun$main$3.apply(nettyserver.scala:289) @ play.core.server.nettyserver$$anonfun$main$3.apply(nettyserver.scala:284) @ scala.option.map(option.scala:145) @ play.core.server.nettyserver$.main(nettyserver.scala:284) @ play.core.server.nettyserver.main(nettyserver.scala) caused by: configuration error: configuration error[] @ play.api.configuration$.play$api$configuration$$configerror(configuration.scala:94) @ play.api.configuration.reporterror(configuration.scala:743) @ play.api.db.bonecpapi.play$api$db$bonecpapi$$error(db.scala:271) @ play.api.db.bonecpapi$$anonfun$getdatasource$3.apply(db.scala:438) @ play.api.db.bonecpapi$$anonfun$getdatasource$3.apply(db.scala:438) @ scala.option.getorelse(option.scala:120) @ play.api.db.bonecpapi.getdatasource(db.scala:438) @ play.api.db.db$$anonfun$getdatasource$1.apply(db.scala:142) @ play.api.db.db$$anonfun$getdatasource$1.apply(db.scala:142) @ scala.option.map(option.scala:145) @ play.api.db.db$.getdatasource(db.scala:142) @ play.api.db.db.getdatasource(db.scala) @ play.db.db.getdatasource(db.java:25) @ play.db.ebean.ebeanplugin.onstart(ebeanplugin.java:54)
so don't understand how can it.
yes!!! i've found it! after debug mode (etc...)
there 2 problems.
first problem : must add key application.conf :
ebeanconfig.datasource
for me (for exemple), postgresql.conf modified :
db.postgresql.driver=org.postgresql.driver db.postgresql.jndiname=defaultds ebean.postgresql="fr.chklang.dontforget.business.*" ebeanconfig.datasource.default=postgresql
second problem : include play 2.3.x don't works because conf folder isn't added classpath (ref load file '/conf' directory on cloudbees ) must concat prod.conf, postgresql.conf , dontforget.conf single file.
i hope have helped other developper...
Comments
Post a Comment