简体   繁体   中英

Play-slick - Is default.db required?

I'm working on an application using Play and Slick. This app requires access to (at least) two databases and this is working fine when one is defined as default and other is named. Eg.,

db.default.driver = "com.mysql.jdbc.Driver"
db.default.url = "jdbc:mysql://localhost:3306/db1"
db.db2.driver = "com.mysql.jdbc.Driver"
db.db2.url = "jdbc:mysql://localhost:3306/db2"

I can then happily access each db as follows

DB.withSession { implicit session => ??? }   
DB("db2").withSession { implicit session => ??? }

However, this doesn't really make sense as there is no reason DB1 should be the default. The DBs contain different types of data, neither is the default, both are important. What I would like is:

db.db1.driver = "com.mysql.jdbc.Driver"
db.db1.url = "jdbc:mysql://localhost:3306/db1"
db.db2.driver = "com.mysql.jdbc.Driver"
db.db2.url = "jdbc:mysql://localhost:3306/db2"

Play-scala barfs at this thought. It needs a default db driver and URL and it needs to be able to connect to it.

Anyone know anyway to change this behaviour or to trick play into thinking it has a default?

UPDATE

To be clear, I've greped my code to ensure that I'm not using DB.withSession anywhere. That is, every time I create a session I use DB("db1").withSession or DB("db2").withSession . However, when I run my test, I still get an exception: Caused by: Configuration error: Configuration error[Slick error : jdbc driver not defined in application.conf for db.default.driver key]

Something somewhere is trying to load the default config.

默认值是只是一个名字,一些便利的功能(withSession和withTransaction没有名称),所以, ,你并不需要有一个默认的连接,如果它不适合你的项目。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM