Slick MSSQL“无法为密钥默认值创建Slick数据库配置”

时间:2016-01-13 04:26:35

标签: sql-server scala playframework slick

我无法使用Slick连接到我们的MSSQL数据库。

我知道我必须使用Slick Extensions并且已经这样做了。以下是我们构建的摘录

lazy val thirdPartyDependencies = Seq(
    ...
    "com.typesafe.slick"    %% "slick-extensions"             % "3.1.0",
    "com.typesafe.play"     %% "play-slick"                   % "1.1.0",
    "com.typesafe.slick"    %% "slick-codegen"                % "3.1.0" % "compile"
)

lazy val allResolvers = Seq(
  "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/",
  "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/",
  "Typesafe Releases" at "http://repo.typesafe.com/typesafe/maven-releases/"
)

这是Slick

的application.conf配置
#Slick configuration.
slick.dbs.default.driver=com.typesafe.slick.driver.ms.SQLServerDriver
slick.dbs.default.db.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
slick.dbs.default.db.url=${?db.default.url}
slick.dbs.default.db.user=${?sql_user}
slick.dbs.default.db.password=${?sql_password}

我使用SourceCodeGenerator工具构建了表定义而没有任何问题。这是连接到数据库的代码:

val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)

我没有任何编译时问题,但在运行代码时会遇到以下堆栈跟踪:

[error] play.api.db.slick.DefaultSlickApi - Failed to create Slick database config for key default.
slick.SlickException: Error getting instance of Slick driver "com.typesafe.slick.driver.ms.SQLServerDriver"
       at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:65) ~[slick_2.11-3.1.0.jar:na]
       at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:89) [play-slick_2.11-1.1.0.jar:1.1.0]
       ...
Caused by: java.lang.InstantiationException: com.typesafe.slick.driver.ms.SQLServerDriver
       at java.lang.Class.newInstance(Class.java:427) ~[na:1.8.0_45]
       at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:63) ~[slick_2.11-3.1.0.jar:na]
       ... 22 common frames omitted
 Caused by: java.lang.NoSuchMethodException: com.typesafe.slick.driver.ms.SQLServerDriver.<init>()
       at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_45]
       at java.lang.Class.newInstance(Class.java:412) ~[na:1.8.0_45]
       ... 23 common frames omitted

我对Slick完全不熟悉。我们有一个商业类型安全许可证,所以我认为我们应该使用其中提供的一些光滑功能。谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

您的application.conf配置文件存在问题。尝试在驱动程序名称的末尾添加一个尾随$,告诉Slick将其称为对象:

slick.dbs.default.driver = "com.typesafe.slick.driver.ms.SQLServerDriver$"

请阅读this SO post了解详情。