如何使用Play 2.5.x Framework
在Slick
中配置和使用多个数据源?
例如,一个数据源应为MySQL
,另一个PostgreSQL
。
slick.dbs.default.driver = "utils.db.TetraoPostgresProfile$"
slick.dbs.default.db.driver = "org.postgresql.Driver"
slick.dbs.default.db.url = "jdbc:postgresql://localhost:5432/templatesite_db"
slick.dbs.default.db.user = "user"
slick.dbs.default.db.password = "pass"
slick.dbs.secondary.driver = "slick.jdbc.MySQLProfile$"
slick.dbs.secondary.db.driver = "com.mysql.jdbc.Driver"
slick.dbs.secondary.db.url = "jdbc:mysql://localhost:3306/dbName"
slick.dbs.secondary.db.user = "root"
slick.dbs.secondary.db.password = "pass"
答案 0 :(得分:0)
这在ScalaDatabase文档页面中直接解决:
// inject "orders" database instead of "default"
class ScalaInjectNamed @Inject()(
@NamedDatabase("orders") db: Database) extends Controller {
// do whatever you need with the db
}
https://www.playframework.com/documentation/2.5.x/PlaySlick#usage
https://www.playframework.com/documentation/2.5.x/ScalaDatabase#obtaining-a-jdbc-connection