问题描述
过去,我曾使用Slick访问服务器中的Vertica数据库.我最近将Slick的版本从2.0升级到了3.1.自升级以来,我遇到一个错误(下面的堆栈跟踪).该错误表明找不到光滑的驱动程序.
In the past I have used Slick to access a Vertica database in a server. I recently upgraded my version of Slick from 2.0 to 3.1. Since the upgrade, I am encountering an error (stack trace below). The error indicates that the slick driver cannot be found.
根据 Slick 3.2.1文档,其他SQL数据库可以是可以通过简化的功能集立即访问".
According to theSlick 3.2.1 docs, "Other SQL databases can be accessed right away with a reduced feature set".
我想知道的是-是否仍然可以使用slick直接支持的数据库中的其他"类型的数据库?如果可以,怎么办?
What I am wondering is - Is it still possible to use an "Other" type of database from those directly supported by slick? If so, how?
我的数据库配置是:
slick.dbs.default.driver="slick.driver.JdbcDriver"
slick.dbs.default.db.driver="com.vertica.jdbc.Driver"
slick.dbs.default.db.url=${some.url}
slick.dbs.default.db.user=${some.user}
slick.dbs.default.db.password=${some.pw}
请注意,感谢,我还尝试了以下每种方法来替换配置中的第一行:
Please note that thanks to this Stack Overflow response, I have also tried each of the following to replace the first line in the config:
slick.dbs.default.driver="slick.driver.JdbcDriver$"
slick.dbs.default.driver="slick.driver.JdbcDriver$class"
slick.dbs.default.driver=slick.driver.JdbcDriver
我的sbt文件中也有
libraryDependencies ++= Seq(
"com.vertica" % "vertica-jdbc" % "7.0.1",
"com.typesafe.play" %% "play-slick" % "2.0.0")
请注意,播放平滑使用平滑3.1.0.
Note that play-slick uses slick 3.1.0.
完整堆栈跟踪:
[ERROR] [10/07/2016 16:43:52.336] [p.a.d.s.DefaultSlickApi] [*] Failed to create Slick database config for key default.
slick.SlickException: Error getting instance of Slick driver "slick.driver.JdbcDriver"
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:65)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:89)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get$lzycompute(SlickApi.scala:81)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get(SlickApi.scala:80)
at play.api.db.slick.DefaultSlickApi.dbConfig(SlickApi.scala:66)
at play.api.db.slick.NamedDatabaseConfigProvider$$anon$1.get(SlickModule.scala:59)
at utils.liger.DimensionMapper.<init>(DimensionMapper.scala:32)
at utils.liger.DimensionMapper$$FastClassByGuice$$1320fe73.newInstance(<generated>)
at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:84)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:181)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:47)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:22)
at play.core.server.ProdServerStart.main(ProdServerStart.scala)
Caused by: java.lang.InstantiationException: slick.driver.JdbcDriver
at java.lang.Class.newInstance(Class.java:427)
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:63)
... 36 common frames omitted
Caused by: java.lang.NoSuchMethodException: slick.driver.JdbcDriver.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 37 common frames omitted
如果我改用:
slick.dbs.default.driver="slick.driver.JdbcDriver$"
然后:
[ERROR] [10/07/2016 16:36:07.701] [p.a.d.s.DefaultSlickApi] [*] Failed to create Slick database config for key default.
slick.SlickException: Error getting instance of Slick driver "slick.driver.JdbcDriver$"
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:65)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:89)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get$lzycompute(SlickApi.scala:81)
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.get(SlickApi.scala:80)
at play.api.db.slick.DefaultSlickApi.dbConfig(SlickApi.scala:66)
at play.api.db.slick.NamedDatabaseConfigProvider$$anon$1.get(SlickModule.scala:59)
at controllers.liger.AwdAutomation.<init>(AwdAutomation.scala:43)
at controllers.liger.AwdAutomation$$FastClassByGuice$$64e5b177.newInstance(<generated>)
at com.google.inject.internal.cglib.reflect.$FastConstructor.newInstance(FastConstructor.java:40)
at com.google.inject.internal.DefaultConstructionProxyFactory$1.newInstance(DefaultConstructionProxyFactory.java:61)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:105)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1016)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:405)
at play.api.inject.RoutesProvider$$anonfun$2.apply(BuiltinModule.scala:82)
at play.api.inject.RoutesProvider$$anonfun$2.apply(BuiltinModule.scala:82)
at scala.Option.fold(Option.scala:158)
at play.api.inject.RoutesProvider.get$lzycompute(BuiltinModule.scala:82)
at play.api.inject.RoutesProvider.get(BuiltinModule.scala:78)
at play.api.inject.RoutesProvider.get(BuiltinModule.scala:77)
at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)
at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:104)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:85)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:267)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:84)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:181)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:47)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:22)
at play.core.server.ProdServerStart.main(ProdServerStart.scala)
Caused by: java.lang.ClassNotFoundException: slick.driver.JdbcDriver$
at java.lang.ClassLoader.findClass(ClassLoader.java:530)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at slick.util.ClassLoaderUtil$$anon$1.loadClass(ClassLoaderUtil.scala:12)
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:62)
... 78 common frames omitted
推荐答案
在Slick 3.0中,不赞成使用通用的jdbc驱动程序slick.driver.JdbcDriver$
(如您在源),然后在版本 3.1 (这说明了错误)
With Slick 3.0 the generic jdbc driver slick.driver.JdbcDriver$
has been deprecated (as you can see from source) and then removed in version 3.1 (this explains the error you are seeing)
现在,使用slick 3.2,可以使用特征 slick.jdbc.JdbcProfile
By now, with slick 3.2, other databases can be supported with a custom implementation of the trait slick.jdbc.JdbcProfile
这篇关于如何在Slick 3.1中使用不受支持的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!