Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
playframework数据库连接设置默认和开发数据库_Playframework_Playframework 2.0 - Fatal编程技术网

playframework数据库连接设置默认和开发数据库

playframework数据库连接设置默认和开发数据库,playframework,playframework-2.0,Playframework,Playframework 2.0,嗨,在我的playframework应用程序中,我想配置几个数据库服务器。我想要一个默认的部署。第二个是发展 目前我只有一个这样的定义: slick { dbs { default { profile = "slick.jdbc.MySQLProfile$" db { driver = "com.mysql.jdbc.Driver" url = "" user = "" password =

嗨,在我的playframework应用程序中,我想配置几个数据库服务器。我想要一个默认的部署。第二个是发展

目前我只有一个这样的定义:

slick {
  dbs {
    default {
      profile = "slick.jdbc.MySQLProfile$"
      db {
        driver = "com.mysql.jdbc.Driver"
        url = ""
        user = ""
        password = 
      }
    }
  }
}
slick {
  dbs {
    default {
      profile = "slick.jdbc.MySQLProfile$"
      db {
        driver = "com.mysql.jdbc.Driver"
        url = ""
        user = ""
        password = 
      }
    },
    development {
      profile = "slick.jdbc.MySQLProfile$"
      db {
        driver = "com.mysql.jdbc.Driver"
        url = ""
        user = ""
        password = 
      }
    }
  }
}
如何添加第二个。。。也许是这样:

slick {
  dbs {
    default {
      profile = "slick.jdbc.MySQLProfile$"
      db {
        driver = "com.mysql.jdbc.Driver"
        url = ""
        user = ""
        password = 
      }
    }
  }
}
slick {
  dbs {
    default {
      profile = "slick.jdbc.MySQLProfile$"
      db {
        driver = "com.mysql.jdbc.Driver"
        url = ""
        user = ""
        password = 
      }
    },
    development {
      profile = "slick.jdbc.MySQLProfile$"
      db {
        driver = "com.mysql.jdbc.Driver"
        url = ""
        user = ""
        password = 
      }
    }
  }
}
对吗?在这种情况下,我如何使用默认值以及何时使用dev数据库


提前感谢。

如果您的应用程序只需要一个数据库,并且您希望将一个用于本地开发,另一个用于生产(显然),那么您只需要谈论一个数据库。配置它们的方法是使用两个不同的
conf
文件,比如对于本地用户使用
application.conf
,对于prod用户使用
prod env.conf
,当用户在prod中启动服务器时,将
prod env.conf
作为参数传递给用户

如果您在一个环境中有多个数据库(例如,如果您必须在本地(或产品)中处理两个不同的数据库),那么您需要使用前面提到的
namedatabase(“dbName”)
injection

更新

sbt
如果未在交互模式下运行,则不会使用
-D
选项。您有两个选项,最简单的是在交互模式下运行

RPs-MacBook-Pro:play RP$ sbt
[info] Loading project definition from /Users/RP/play/project
[info] Resolving key references (11994 settings) ...
[info] Set current project to play (in build file:/Users/RP/play/)
[play] $
然后执行
~run“-Dconfig.file=conf/application-dev.conf”
,它应该可以正常工作

另一个选项是导出系统变量(例如:
APP_DEV_CONF_FILE
),并在
build.sbt

val devConfigFile = sys.env.get("APP_DEV_CONF_FILE") match {
  case Some(config) => config
  case None => "application-prod"
}

javaOptions in run ++= Seq(
  "-Dconfig.file=conf/" + devConfigFile + ".conf"
)

有了它,您可以直接使用
sbt run
,无需在交互模式下运行。

您是在一个环境中有多个数据库(如在prod中)还是希望将一个用于本地,一个用于生产?我希望将一个用于本地开发,一个用于生产我尝试了这个:
sbt“~run 9001-Dconfig.file=./conf/application-dev.conf“
但是不同的配置被忽略了我也可以在windows上执行此操作吗?是的,您可以,只需确保路径中的
sbt\bin
。在命令提示符下,转到项目主目录,其中有
build.sbt
,然后执行
sbt
并输入。。您将处于SBT交互模式