Apache 从lift scala中的props文件读取DB凭据

Apache 从lift scala中的props文件读取DB凭据,apache,scala,properties,jetty,lift,Apache,Scala,Properties,Jetty,Lift,我刚开始使用Scala和升降机框架。我正在尝试使用普通的JDBC连接我的数据库。我希望从default.props文件中读取我的DB凭据。到目前为止,我尝试了以下代码: 在我的default.props文件中: db.class=com.mysql.jdbc.Driver db.url=jdbc:mysql://localhost/scalatest db.user=root db.password= 在我的boot.scala文件中,我尝试执行如下JDBC连接: val filename =

我刚开始使用Scala和升降机框架。我正在尝试使用普通的JDBC连接我的数据库。我希望从default.props文件中读取我的DB凭据。到目前为止,我尝试了以下代码: 在我的default.props文件中:

db.class=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost/scalatest
db.user=root
db.password=
在我的boot.scala文件中,我尝试执行如下JDBC连接:

val filename = "/src/main/resources/props/default.props"
Props.whereToLook = () => ((filename, () => Full(new FileInputStream(filename))) :: Nil)

val DBDriver = Props.get("db.class").toString
val DBURL =  Props.get("db.url").toString
val DBUsrName =  Props.get("db.user").toString
val DBPass = Props.get("db.password").toString

Class.forName(DBDriver)
val conn  = DriverManager.getConnection(DBURL,DBUsrName, DBPass)

但在使用container:start命令运行服务器时,会显示fileNotFoundException。有人能告诉我在这里要做什么吗。thanx。删除您更改道具的行。

从何处查看
。它应该已经设置为正确的值。()


注意:
src/main/resources
文件夹的内容通常会在运行时直接添加到类路径中。因此,文件
src/main/resources/props/default.props
应该可以通过调用
someClassInYourProject.getResourceAsStream(“/props/default.props”)
获得。不要试图在运行时引用源目录中的文件,因为它只会在以后引起麻烦。

删除您更改
道具的行。whereToLook
。它应该已经设置为正确的值。()

注意:
src/main/resources
文件夹的内容通常会在运行时直接添加到类路径中。因此,文件
src/main/resources/props/default.props
应该可以通过调用
someClassInYourProject.getResourceAsStream(“/props/default.props”)
获得。不要试图在运行时引用源目录中的文件,因为它只会在以后引起麻烦