0
我在这里查看文档:https://www.playframework.com/documentation/2.6.x/ScalaDatabase#How-to-configure-several-data-sources。使用在playframework 2.6中配置多个连接池
# Orders database
db.orders.driver=org.h2.Driver
db.orders.url="jdbc:h2:mem:orders"
# Customers database
db.customers.driver=org.h2.Driver
db.customers.url="jdbc:h2:mem:customers"
,你可以在代码中引用:
package controllers
import javax.inject.Inject
import play.api.mvc.{BaseController, ControllerComponents}
import play.api.db.{Database, NamedDatabase}
// inject "orders" database instead of "default"
class ScalaInjectNamed @Inject()(
@NamedDatabase("orders") db: Database,
val controllerComponents: ControllerComponents
) extends BaseController {
// do whatever you need with the db
}
但你如何自定义每个连接的连接池可以定义多个数据库连接?
根据此文档:https://www.playframework.com/documentation/2.6.x/SettingsJDBC您可以指定默认配置,数据库等连接池的原型设置等。我如何定义每个连接池的设置?也许一个连接池只需要一个连接,另一个需要更多连接。
感谢