因此,我试图修改一种类型安全激活器模板以使用SQLite数据库,而不是内置的H2数据库。这是原始模板https://github.com/playframework/playframework/tree/master/templates/play-scala-intro
我所做的是将application.conf文件更改为具有以下几行:
slick.dbs.default.driver=slick.driver.SQLiteDriver
slick.dbs.default.db.driver=org.sqlite.JDBC
slick.dbs.default.db.url="jdbc:sqlite:/home/marcin/play-scala-intro/people.db"
当然,我也创建了文件本身(touch people.db
也是如此)。然后,如果我启动我的应用程序,则会出现以下错误:
[info] ! @6ooe822f0 - Internal server error, for (GET) [/] ->
[info]
[info] play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
[info] at play.api.Configuration$.configError(Configuration.scala:178) ~[play_2.11-2.4.6.jar:2.4.6]
[info] at play.api.Configuration.reportError(Configuration.scala:829) ~[play_2.11-2.4.6.jar:2.4.6]
[info] at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:93) ~[play-slick_2.11-1.1.1.jar:1.1.1]
[info] at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get$lzycompute(SlickApi.scala:81) ~[play-slick_2.11-1.1.1.jar:1.1.1]
[info] at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get(SlickApi.scala:80) ~[play-slick_2.11-1.1.1.jar:1.1.1]
我正在寻找一些示例,如此处所示进行设置https://groups.google.com/forum/#!msg/scalaquery/07JBbnZ5VZk/7D1_5N4uGjsJ
或这里:
https://github.com/playframework/play-slick
但是它们与我的代码不够相似,并且由于我对所有这些都不熟悉,因此我无法真正弄清楚如何使用它们。感谢帮助,谢谢!
[编辑]:
根据注释的建议,我在驱动程序名称的末尾添加了“ $”,现在conf文件中的内容看起来像这样:
slick.dbs.default.driver=slick.driver.SQLiteDriver$
slick.dbs.default.db.driver=org.sqlite.JDBC
slick.dbs.default.db.url="jdbc:sqlite:/home/marcin/play-scala-intro/people.db"
在某种意义上,会出现另一个错误:
[info] Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported, connection test query must be configured
[info] at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441) ~[HikariCP-java6-2.3.7.jar:na]
[info] at com.zaxxer.hikari.pool.BaseHikariPool$1.run(BaseHikariPool.java:413) ~[HikariCP-java6-2.3.7.jar:na]
[info] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_66]
我玩的很流畅,SQLite项目:https://github.com/aukgit/scala-open-real-time-bidding-rtb
它也有一个存储库模式。
请签出https://github.com/aukgit/scala-open-real-time-bidding-rtb/releases/tag/v0.0.5
给出一个如何使用SQLite的例子:
import slick.jdbc.SQLiteProfile.api._ // must import
lazy val db = Database.forURL(url = AbsoluteDatabasePath)
您可以下载该版本中的存储库并使用SBT运行它
run sbt
或使用IntelliJ IDEA打开
class RtbServiceBasicRouter @Inject()(
controller : RequestSimulatorServiceApiController)
extends SimpleRouter {
val routingActionWrapper : ControllerGenericActionWrapper = ControllerGenericActionWrapper(
ControllerDefaultActionType.Routing)
override def routes : Routes = {
try {
case GET(p"/serviceName") | GET(p"/") =>
controller.getServiceName()
case GET(p"/commands") | GET(p"/available-commands") | GET(p"/routes") =>
controller.getAvailableCommands()
case GET(p"/bannerRequest") =>
controller.getBannerRequestSample()
} catch {
case e : Exception =>
controller.handleError(e, routingActionWrapper)
throw e
}
}
}
将路由控制器添加到路由(https://github.com/aukgit/scala-open-real-time-bidding-rtb/blob/6bf6beb6adb93b83cba49085d2d33269502189e1/conf/routes)
-> /services/v1/rtbSimulateService controllers.controllerRoutes.routerGeneric.RtbServiceBasicRouter